Open northern opened 4 years ago
Building with --no-minify
throws yet another error:
Error: Cannot use GraphQLObjectType "Query" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
(Related issue: https://github.com/parcel-bundler/parcel/issues/2327)
I ran into this same issue with apollo-server-lambda.
Related issue here apollographql/apollo-server#3808
Apollo is using module.require to load node's crypto library in node-like environments: https://github.com/apollographql/apollo-server/blob/8b02c0c440928d6b1d4e8c6d79a9d27f2a528666/packages/apollo-server-core/src/utils/createSHA.ts#L7
I just had a quick look, not familiar with Parcel internals, but looks like the modules created by Parcel dont include module.require https://github.com/parcel-bundler/parcel/blob/d24e09a9797af41a9d2c6c733b1c6cf6671d60c7/packages/core/parcel-bundler/src/builtins/prelude.js#L45
Any ideas?
in my case, I'm getting this error because module.require
is tree-shaked to null
, but should be undefined
I'm using purescript-debug
library, which should work on both browser and node
it has these lines
// Alias require to prevent webpack or browserify from actually requiring.
var req = typeof module === "undefined" ? undefined : module.require;
var util = req === undefined ? undefined : req("util");
webpack tree shakes this to undefined
, so this works fine
(NOTE: I didnt check for sure how webpack transformes, but I remember it works fine with purescript-debug)
but parcel:
--no-minify
compiles to // Alias require to prevent webpack or browserify from actually requiring.
var $Ttyb$var$req = "object" === "undefined" ? undefined : null;
var $Ttyb$var$util = $Ttyb$var$req === undefined ? undefined : $Ttyb$var$req("util");
--no-minify
it compiles AND tree shakes to var UA = null
, VA = void 0 === UA ? void 0 : UA("util")
as you see if UA = undefined
- it would tree-shake even further to VA = void 0
module.require
should be transformed to undefined
(not to null
)
🐛 bug report
🎛 Configuration (.babelrc, package.json, cli command)
🤔 Expected Behavior
I expect the compiled prod server to start just like the dev server does.
😯 Current Behavior
When I build my node project with the
--bundle-node-modules
option and then when I run the project, I get the following error:However, without the
--bundle-node-modules
option, the project runs as expected (but I require the single compiledindex.js
).💁 Possible Solution
N/A
🔦 Context
I spend a fair bit of time trying to figure out how to resolve this issue but I clearly need some expert help.
💻 Code Sample
To reproduce, use the following directory structure:
To run dev server use:
npm run dev
. Browse tolocalhost:4000/graphql
will bring up the GraphQL Playground.To build the prod server use:
npm run dist
. This will place the compiled server inbin/index.js
To run the prod server use:
npm run start
. This will exit with error:🌍 Your Environment