graphql-js: Compile error with webpack 4
Hi,
After updating to webpack 4, compiling graphiql doesn’t work because of the graphql-js dependency.
I get a bunch of those errors:
ERROR in ./node_modules/graphql/index.mjs
2:0-49 Can't reexport the named export 'graphql' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./node_modules/graphiql/dist/components/GraphiQL.js
@ ./node_modules/graphiql/dist/index.js
@ ./src/client/apps/graphiql/graph-viewer/index.js
@ ./src/client/apps/graphiql/app.js
@ ./src/client/apps/graphiql/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/client/apps/graphiql
ERROR in ./node_modules/graphql/index.mjs
2:0-49 Can't reexport the named export 'graphqlSync' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./node_modules/graphiql/dist/components/GraphiQL.js
@ ./node_modules/graphiql/dist/index.js
@ ./src/client/apps/graphiql/graph-viewer/index.js
@ ./src/client/apps/graphiql/app.js
@ ./src/client/apps/graphiql/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/client/apps/graphiql
ERROR in ./node_modules/graphql/index.mjs
39:0-61:50 Can't reexport the named export 'DEFAULT_DEPRECATION_REASON' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./node_modules/graphiql/dist/components/GraphiQL.js
@ ./node_modules/graphiql/dist/index.js
@ ./src/client/apps/graphiql/graph-viewer/index.js
@ ./src/client/apps/graphiql/app.js
@ ./src/client/apps/graphiql/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/client/apps/graphiql
ERROR in ./node_modules/graphql/index.mjs
39:0-61:50 Can't reexport the named export 'GraphQLBoolean' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./node_modules/graphiql/dist/components/GraphiQL.js
@ ./node_modules/graphiql/dist/index.js
@ ./src/client/apps/graphiql/graph-viewer/index.js
@ ./src/client/apps/graphiql/app.js
@ ./src/client/apps/graphiql/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/client/apps/graphiql
ERROR in ./node_modules/graphql/index.mjs
39:0-61:50 Can't reexport the named export 'GraphQLDeprecatedDirective' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./node_modules/graphiql/dist/components/GraphiQL.js
@ ./node_modules/graphiql/dist/index.js
@ ./src/client/apps/graphiql/graph-viewer/index.js
@ ./src/client/apps/graphiql/app.js
@ ./src/client/apps/graphiql/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/client/apps/graphiql
(and a million more)
Seems like forcing the downgrade to a graphql-js version that doesn’t have .mjs files fixes the issue.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 59
- Comments: 26 (3 by maintainers)
Links to this issue
Commits related to this issue
- Fix .mjs issue with GraphQL 0.13.2 https://github.com/graphql/graphql-js/issues/1272#issuecomment-377384574 — committed to ericclemmons/razzle by ericclemmons 6 years ago
- Fix .mjs issue with GraphQL 0.13.2 (#715) * Fix .mjs issue with GraphQL 0.13.2 https://github.com/graphql/graphql-js/issues/1272#issuecomment-377384574 * Fix .mjs still referencing "require" ... — committed to jaredpalmer/razzle by ericclemmons 6 years ago
- Fix issue with .mjs files See: https://github.com/graphql/graphql-js/issues/1272\#issuecomment-393903706 — committed to Codaisseur/LearnReactQL by deleted user 6 years ago
- Sync the next branch with master (#794) * v2 (#630) * Webpack v4 (#525) * (feat) Adds webpack v4, removes CommonsChunkPlugin and sets mode * (feat) Yarn locks * (feat) Removes NamedModule... — committed to jaredpalmer/razzle by nimaa77 6 years ago
- Change extensions ordering as described in comment: https://github.com/graphql/graphql-js/issues/1272#issuecomment-377384574 — committed to dumbNickname/storybook by dumbNickname 6 years ago
- feat(app): out of the box support for .mjs files #6689 — committed to quasarframework/quasar by rstoenescu 4 years ago
- chore(internal): setup `dendron-plugin-views` build to prefer `main` entry field References - https://github.com/webpack/webpack/issues/6459#issuecomment-373723979 - https://github.com/graphql/graph... — committed to dendronhq/dendron by namjul 2 years ago
- chore(internal): setup `dendron-plugin-views` build to prefer `main` entry field References - https://github.com/webpack/webpack/issues/6459#issuecomment-373723979 - https://github.com/graphql/graph... — committed to dendronhq/dendron by namjul 2 years ago
- chore: fix `dendron-plugin-views` build (#3775) * chore: fix `dendron-plugin-views` build This aim of this commit is to fix the build task within `dendron-plugin-views` package which currently resul... — committed to dendronhq/dendron by namjul 2 years ago
- chore: fix `dendron-plugin-views` build (#3775) * chore: fix `dendron-plugin-views` build This aim of this commit is to fix the build task within `dendron-plugin-views` package which currently resul... — committed to dendronhq/dendron by namjul 2 years ago
It looks like manually supplying extensions may cause this issue - which is common for those who save their files as
.jsx. If you do this, make sure that.mjsremains in the list of extensions and appears before.js.For anyone else who stumbles into this, I found the following to solve the problem by adding to rules:
and to resolve:
@jatsrt I didn’t have to include that loader once I put
.mjsbefore.jsin myresolve.extensions. Mine is nowextensions: ['.wasm', '.mjs', '.js', '.jsx', '.json'],I think graphql should add “browser” field in package.json since webpack4 could resolve mjs now, any usage to graphql in browser will compiled failed.
BTW, I have change configuration of webpack add following part to force webpack ignore .mjs file, this also work. But all packages will be loaded following the “main” field in package.josn
resolve: { mainFields: [‘browser’, ‘main’, ‘module’], extensions: [‘.js’, ‘.json’, ‘.jsx’] },
Adding
.mjsto the list of extensions worked (before .js and .jsx)Reference: https://github.com/graphql/graphql-js/issues/1272#issuecomment-377384574
For lazy people wanting a specific version number: downgrading to v0.13.0 fixed the issue for me.
Thanks for the report, we’ll follow up with the webpack team to understand why this isn’t working as expected.
Had the same issue, but I didn’t want to mess with webpack config. My fix was to change imports.
If somebody uses
chainWebpack:And for anyone running into this in a Quasar app, you can add the
.mjssupport by adding it into quasar.config.js, in the rules pushed in thebuild.extendWebpackconfig. e.g.:I started getting these warnings/errors after changing my backend’s folder structure around while trying to run serverless-offline. The fix for me was to change this line in my webpack config
externals: [ nodeExternals() ],to
externals: [ nodeExternals({ modulesDir: path.resolve(__dirname, 'node_modules') }) ],I did NOT have to add ‘.mjs’ to extensions or a new rule. This fix probably doesn’t apply to you if you are using a standard folder structure. I don’t even know why this worked.
I have connected issue caused by
I have 3 environments: development, staging and production. I’m using AWS mobile hub, for each env, I have separate config, which I import with
The problem is that after adding the rule above to webpack config, require stops working in browser, but still working on server-side with same webpack config
adding .mjs to the list of extensions worked for me after I went back and set everything back to import {} from “graphql”
@jiawang1
Hmm I’m a bit confused could you post your webpack config?