-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't import the named export 'RestError' from non EcmaScript module (only default export is available) #22172
Comments
The conditional export feature may be a solution.
We need to be careful about state though |
Let me make sure I understand the issue here:
The request then is to expose our MJS version to Node's native ES Module support. In order to do that, we must use conditional imports and either:
If we go with 1, we have to validate that older Node runtimes understand how to load Am I missing anything? |
It seems like |
@jeremymeng Any updates on this? |
@mpodwysocki this is related to the investigation you are doing for native Node module support |
@xirzec correct, we could fix this with the exports and ESM modules |
React native apps still use v4 and that is why we had to support the v4 version too. @jeremymeng Thank you for sharing the StackOverflow links. @davidyuk we can see these solution work or wait till the #22804 gets merged into master. |
I did some testing with @subhod-i's repro project. With PR #22804, webpack 4 now reports a different error:
Importing from a .mjs file in a simple project works fine when webpack is not involved. It feels that webpack doesn't work very well with ESM. I will continue to check if there's anything we can do. |
It is still not clear to me why from a .mjs file, webpack couldn't use the import crp from '@azure/core-rest-pipeline';
console.log(crp.RestError); |
This would work in create-react-app@4, but won't work in create-react-app@5 as I know. The thing is that we are library that depends on an api generated by autorest and would like to be compatible with both create-react-app@4 and create-react-app@5, I don't see a way to import @azure/core-rest-pipeline in a way compatible with both.
webpack@4 has a quirk, but it is doable to fix this on the side of your package, e.g. using mjs extension or adding
I'm not sure about this, probably they are using their own builder, so, the issue is only aboue compatibility with create-react-app@4
As I know, we can't add |
@davidyuk I added |
- Add conditional exports for core-rest-pipeline - Add .js extension to imported source module name - Bump dev dependency Mocha version to v10 - Add `ts-node/esm` loader in mocha config - Update npm scripts - Update linter rule to allow dist/index.cjs - Add a copy of our typing files for cjs - Bump minor version ### Packages impacted by this PR `@azure/core-rest-pipeline` ### Issues associated with this PR #22172
- Add conditional exports for core-rest-pipeline - Add .js extension to imported source module name - Bump dev dependency Mocha version to v10 - Add `ts-node/esm` loader in mocha config - Update npm scripts - Update linter rule to allow dist/index.cjs - Add a copy of our typing files for cjs - Bump minor version ### Packages impacted by this PR `@azure/core-rest-pipeline` ### Issues associated with this PR #22172
Hi @subhod-i, we deeply appreciate your input into this project. Regrettably, this issue has remained unresolved for over 2 years and inactive for 30 days, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support. |
Describe the bug
Trying to perform
import { RestError } from '@azure/core-rest-pipeline';
in a ECMAScript Module file (.mjs).
returns build error with the message
Can't import the named export 'RestError' from non EcmaScript module (only default export is available)
To Reproduce
Steps to reproduce the behavior:
I have created a simple project to demonstrate this
git clone git@github.com:subhod-i/react-app-4.git
cd react-app-4
npm i
npm start
Expected behavior
Support for ECMA module files.
Additional context
The same problem is observed in
@azure/core-client
package too.The text was updated successfully, but these errors were encountered: