question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import the named export 'XXX' from non EcmaScript module (only default export is available)

See original GitHub issue

Describe the bug

When depending on a package with a module with an ‘mjs’ extension, CRA does not load. This seems to be something CRA-related, because having an extension .mjs for modules is one of the (ammitedly MANY different) extension documented for ES6 modules. For example, it is one of the defaults in webpack: https://webpack.js.org/configuration/resolve/#resolveextensions.

I am aware that changing the extension will make these dependencies work, but I am a bit afraid other tools may come up in the future with different wishes regarding extensions, having us to choose between supporting CRA vs that other hypothetical tool.

Did you try recovering your dependencies?

I have a new and freshly made CRA here: https://github.com/DrRataplan/cra-mjs-repro. Check it out, install it and run npm start. Observe the error Can't import the named export 'compileVM' from non EcmaScript module (only default export is available).

Which terms did you search for in User Guide?

I searched for ‘mjs’, the exact error etc. No usable results. I did find a number of related issues though: https://github.com/reactioncommerce/reaction-component-library/issues/399 and https://github.com/formatjs/formatjs/issues/1395 for example, but they all reverted back to using ‘create-react-app-rewired’ to fix this issue for themselves. I am actually a maintainer for a package that is affected by this, and I would like my users to not revert to workarounds if they want to use my library in CRA.

Environment

npx: installed 67 in 3.415s

Environment Info:

  current version of create-react-app: 4.0.1
  running from /home/martin/.npm/_npx/275930/lib/node_modules/create-react-app

  System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 14.8.0 - ~/.nvm/versions/node/v14.8.0/bin/node
    Yarn: Not Found
    npm: 6.14.11 - ~/.nvm/versions/node/v14.8.0/bin/npm
  Browsers:
    Chrome: 87.0.4280.141
    Firefox: 84.0.1
  npmPackages:
    react: ^17.0.1 => 17.0.1 
    react-dom: ^17.0.1 => 17.0.1 
    react-scripts: 4.0.1 => 4.0.1 
  npmGlobalPackages:
    create-react-app: Not Found

(But this happens in all environments I have seen so far.

Steps to reproduce

  1. Make a new CRA
  2. Install a package with a .mjs module export. something with a dependency with a .mjs export. Such as xspattern, fontoxpath, etc. I chose xspattern in the reproducable case: https://github.com/DrRataplan/cra-mjs-repro
  3. Import this package
  4. npm start
  5. Observe error

Expected behavior

It just works. I can just npm install any package (that is expected to work in the browser). CRA will configure Webpack to just load the main extensions as ES6 modules.

Actual behavior

A crash: image

Reproducible demo

https://github.com/DrRataplan/cra-mjs-repro

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:34
  • Comments:8

github_iconTop GitHub Comments

8reactions
onichandamecommented, Aug 25, 2021

seeing the same error with @graphql-tools/mock

6reactions
MichelMLcommented, Dec 8, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't import the named export 'Component' from non ... - GitHub
Can't import the named export 'Component' from non EcmaScript module (only default export is available) #1395.
Read more >
Can't import the named export 'XXX ... - Stack Overflow
Can't import the named export 'XXX' (imported as 'XXX') from default-exporting module (only default export is available) · Subscribe to RSS.
Read more >
can't import the named export from non ecmascript module ...
Can't import the named export 'XXX' from non EcmaScript module (only default export is available) #10356.
Read more >
vue3报错:Can't import the named export 'computed' from non ...
vue3报错:Can't import the named export 'computed' from non EcmaScript module (only default export is available)
Read more >
Why can't I import classes without 'export default' in ES6?
There are various type of exports : Named Export: [code ]export class A1 {} export class B1 ... you are only importing the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found