Import error with CRA v2 (webpack 4)
See original GitHub issuedescription
Using create-react-app v2, an error is thrown on start : “Can’t import the named export ‘AUTH_CHECK’ from non EcmaScript module”
workaround
add type: 'javascript/auto',
in module section of webpack.config.js
.
explanation
modules with mjs
extension are now treated differently by webpack 4 :
Files ending with .mjs are parsed as javascript/esm, a stricter mode. This mode does not allow to import CJS modules like ESM ones.
source : https://github.com/apollographql/react-apollo/issues/1737
Similar issue with react-appolo :
In react-apollo, react-apollo.browser.umd.js is evaluated by webpack as javascript/auto (webpack 3 default mode). It is a loose mode to preserve compatibility that support both CJS and ESM within the same file. When webpack parses require(“./ApolloProvider”) it will look at ./ApolloProvider.mjs first.
While this issue looks like a webpack one, it is not: react-apollo should correctly import non-ESM dependencies, in this case react.
version
react-admin-firebase v0.5.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
Fixed the issue, please upgrade to version
0.5.3
and please advise if there’s any problems.Issue
The
.mjs
reference has been removed, socreate-react-app
won’t look for it anymore.Commit: #0bccf9b
Thanks everyone for reporting the issue! 👍 Ben
Well as I understood it now webpack 4 treats modules with
.mjs
extension differently, and as a result only default exports are allowed.This is the error on standard CRA (v2) : https://codesandbox.io/s/723r5p804q
Will try to submit a PR this week end