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.
When bundling graphql-js with webpack, e.g. as dependency of graphiql, you get this error at runtime:
This is because
instanceOf.jscontains a reference toprocess.env: https://github.com/graphql/graphql-js/blob/dec24f9/src/jsutils/instanceOf.js#L19-L36In the ESM build, which is used by webpack by following the
modulefield in package.json, the file gets compiled to a.mjsfile, which does not get applied the webpackProvidePlugin, see webpack/webpack#7032.This makes it impossible to bundle
graphiqlwith webpack.