aepp-sdk-js icon indicating copy to clipboard operation
aepp-sdk-js copied to clipboard

Fix compatibility with create-react-app@4

Open davidyuk opened this issue 2 years ago • 8 comments

Recently I find out that api generated by autorest can't be build in create-react-app@4 with error:

Failed to compile.

./node_modules/@aeternity/aepp-sdk/es/apis/node/node.mjs
Can't import the named export 'ServiceClient' from non EcmaScript module (only default export is available)

node.mjs contains

import * as coreClient from "@azure/core-client";

As a workaround I made a patch https://github.com/aeternity/babel-plugin-transform-default-named-imports/commit/a4a149b1473114dacc29ec939d98bfa388117e88 to babel-plugin-transform-default-named-imports that rewrites it to:

import coreClient from "@azure/core-client";

The oridinal issue probably because azure packages doesn't formatted properly to work in this case (have mjs file extension or type: module in package.json).

Also, would be nice if babel-plugin-transform-default-named-imports supports rewriting a namespace import to a default one (as I implemented in my patch).

I'm asking @subhod-i to investigate this and to send a PR to the babel plugin and to open an issue in one of autorest repos.

davidyuk avatar May 24 '22 06:05 davidyuk

https://github.com/formatjs/formatjs/issues/1395

subhod-i avatar Jun 06 '22 08:06 subhod-i

@Kalovelo @martinkaintas

subhod-i avatar Jun 06 '22 09:06 subhod-i

https://github.com/Azure/azure-sdk-for-js/issues/22172 Created an issue on the azure-sdk-for-js repository. Let's revisit once the issue is closed.

subhod-i avatar Jun 09 '22 08:06 subhod-i

let's just drop out of the box compatibility with react-scripts@4 and add a link to https://stackoverflow.com/questions/64002604/how-to-make-create-react-app-support-mjs-files-with-webpack or so to compatibility table

davidyuk avatar Aug 15 '22 19:08 davidyuk

I think the react application is now working with latest SDK release where the circular dependency was removed.

tested https://github.com/subhod-i/aepp-boilerplate-react today. I talked to @ifaouibadi to revisit this and provide a PR to the "official" react boilerplate repo of Emmanuel once reay

marc0olo avatar Aug 15 '22 20:08 marc0olo

the problem is not in circular dependencies (we had it before), but in imports of cjs modules from mjs in webpack@4 with default configuration. For example, because of this problem we can't import autorest in react-scripts@4

davidyuk avatar Aug 17 '22 12:08 davidyuk

@ifaouibadi is this a blocker / problem for the boilerplate right now?

marc0olo avatar Aug 17 '22 12:08 marc0olo

@marc0olo it works fine, btw after the update the boilerplate uses react-scripts@4

ifaouibadi avatar Aug 17 '22 15:08 ifaouibadi