- Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
When bundling graphql-js with webpack, e.g. as dependency of graphiql, you get this error at runtime:
ReferenceError: require is not defined at Module.../sourcegraph/node_modules/graphql/jsutils/instanceOf.mjs (instanceOf.mjs:28) at __webpack_require__ (bootstrap:63) at Module.../sourcegraph/node_modules/graphql/type/definition.mjs (definition.mjs:1) at __webpack_require__ (bootstrap:63) at Module.../sourcegraph/node_modules/graphql/type/validate.mjs (validate.mjs:1) at __webpack_require__ (bootstrap:63) at Module.../sourcegraph/node_modules/graphql/graphql.mjs (graphql.mjs:1) at __webpack_require__ (bootstrap:63) at Module.../sourcegraph/node_modules/graphql/index.mjs (index.mjs:2) at __webpack_require__ (bootstrap:63) This is because instanceOf.js contains a reference to process.env: https://github.com/graphql/graphql-js/blob/dec24f9/src/jsutils/instanceOf.js#L19-L36
In the ESM build, which is used by webpack by following the module field in package.json, the file gets compiled to a .mjs file, which does not get applied the webpack ProvidePlugin, see webpack/webpack#7032.
This makes it impossible to bundle graphiql with webpack.
ryanwiesjahn, alexandercarls, tomeightyeight and six7
Metadata
Metadata
Assignees
Labels
No labels