Skip to content
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

Import error with CRA v2 (webpack 4) #14

Closed
capi1O opened this issue Apr 25, 2019 · 6 comments
Closed

Import error with CRA v2 (webpack 4) #14

capi1O opened this issue Apr 25, 2019 · 6 comments

Comments

@capi1O
Copy link

capi1O commented Apr 25, 2019

description

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 : apollographql/react-apollo#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

@benwinding
Copy link
Owner

Hi @monkeydri,
Thanks for reporting this issue. Sorry I don't really understand this, would you be able to explain the issue in a little more detail? Or make a pull request to fix this?
Cheers,
Ben

@capi1O
Copy link
Author

capi1O commented Apr 29, 2019

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

@jevin
Copy link

jevin commented May 6, 2019

@monkeydri, any update on the PR?

@benwinding
Copy link
Owner

benwinding commented May 7, 2019 via email

@jevin
Copy link

jevin commented May 7, 2019

Thanks guys!

@benwinding
Copy link
Owner

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, so create-react-app won't look for it anymore.

Commit: #0bccf9b

Thanks everyone for reporting the issue! 👍
Ben

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants