-
Notifications
You must be signed in to change notification settings - Fork 787
webpack 4 compatibility issue #1737
Comments
Seems to be the same/similar issue as #1734 |
Does anyone know of a workaround? |
Update: It looks like the solution is to not use Update: If you use ESM with |
Adding this to the webpack config rules section worked for me:
|
@eldh I used a similar approach: {
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
}, |
@eldh @ooflorent Nice! Just remember Webpack's defaults are the way they are for a reason. |
Yeah for sure, definitely not meant as a long-term solution! Is there a specific reason react-apollo uses .mjs? Should that perhaps be changed to .js for now? (Seems like a tiny change to the build script to do so.) |
@eldh (I'm not a maintainer) but it looks like it was done as part of a PR to provide esm and cjs variants and they just used |
Yeah, I know. :) Maybe @rosskevin @jaydenseric @jbaxleyiii wants to chime in? |
FWIW Inferno.js just switched from |
@eldh I have been pushing for a proper adoption of native ESM hard here for a while now as I have had great success using it in production for my GraphQL API servers and would love to be able to use it everywhere else too. Propper The best issue to track regarding support for native ESM via @jdalton I've explained basics in the contributor Slack before, during and after every Apollo
I'm less invested in bringing native ESM to client side Apollo packages now that |
Note: |
Confirmed reverted/working in 2.1.1 as cjs with webpack 4. |
There seems to be a compatability issues with the `.mjs` file extension: apollographql/react-apollo#1737 This moves away from that extension so that this works in more environments. Fixes #2.
tried to switch to beta 6 and got the following webpack errors: > Can't import the named export 'createElement' from non EcmaScript module (only default export is available) A bit of searching showed that there's a problem with default webpack config and packages that export .mjs files. More details here apollographql/react-apollo#1737 This PR removes the mjs entry from package.json.
tried to switch to beta 6 and got the following webpack errors: > Can't import the named export 'createElement' from non EcmaScript module (only default export is available) A bit of searching showed that there's a problem with default webpack config and packages that export .mjs files. More details here apollographql/react-apollo#1737 This PR removes the mjs entry from package.json.
There seems to be a compatability issues with the `.mjs` file extension: apollographql/react-apollo#1737 This moves away from that extension so that this works in more environments. Fixes #2.
Intended outcome:
I'm migrate a project that uses
react-apollo@2.1.0-beta.3
from webpack 3 to webpack 4. Once the configuration updated, the build must succeed.Actual outcome:
The build fails in webpack 4:
webpack 4 favors
.mjs
over.js
files and applies stricter rules when dealing with Harmony modules. Within a Harmony module, you can only import CJS modules asdefault
. The following imports would raise an error sincereact
is not a Harmony module:In
react-apollo
,react-apollo.browser.umd.js
is evaluated by webpack asjavascript/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 parsesrequire("./ApolloProvider")
it will look at./ApolloProvider.mjs
first. Files ending with.mjs
are parsed asjavascript/esm
, a stricter mode. This mode does not allow to import CJS modules like ESM ones.While this issue looks like a webpack one, it is not:
react-apollo
should correctly import non-ESM dependencies, in this casereact
.How to reproduce the issue:
Install dependencies:
Create
src/index.js
:Build:
Version
The text was updated successfully, but these errors were encountered: