parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.4k stars 2.26k forks source link

Node bundle produces erroring index.js file #2327

Open Siyfion opened 5 years ago

Siyfion commented 5 years ago

I've briefly spoken to @devongovett on Twitter about this issue, following a conversation about Zeit's ncc.

In short, ncc successfully builds & runs the project: https://gist.github.com/Siyfion/a522d87d8c55fa6ef8211cd2fa5a005f

But Parcel fails: https://gist.github.com/Siyfion/586ac0d1da5585710789a942153a65fd

With the runtime error being:

Error: Cannot use e "__Schema" 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.

The project is a pretty simple Apollo Server starter project, nothing unusual in that sense.

mischnic commented 5 years ago

Can you provide some code to reproduce it?

Siyfion commented 5 years ago

The Apollo example even has the same issue: https://github.com/apollographql/graphql-server-example

mischnic commented 5 years ago

Non-minified error: graphql doesn't seem to like the way parcel does the bundling?

.../dist/index.js:30346
      throw new Error('Cannot use ' + className + ' "' + value + '" from another module or realm.\n\nEnsure that there is only one instance of "graphql" in the node_modules\ndirectory. If different versions of "graphql" are the dependencies of other\nrelied on modules, use "resolutions" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate "graphql" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results.');
      ^

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.
    at instanceOf (.../dist/index.js:30346:13)
    at isObjectType (.../dist/index.js:30728:34)
    at typeMapReducer (.../dist/index.js:35287:36)
    at Array.reduce (<anonymous>)
    at new GraphQLSchema (.../dist/index.js:35178:28)
    at Object.buildASTSchema (.../dist/index.js:47285:10)
    at Object.buildSchemaFromTypeDefinitions (.../dist/index.js:71265:28)
    at Object.makeExecutableSchema (.../dist/index.js:71566:29)
    at new ApolloServerBase (.../dist/index.js:103442:37)
    at new ApolloServer (.../dist/index.js:109609:1)
mischnic commented 5 years ago

Just for the record: scope-hoisting doesn't work either

Cannot read property 'optional' of undefined
    at CallExpression (.../parcel/packages/core/parcel-bundler/src/scope-hoisting/concat.js:148:66)
    at NodePath._call (.../parcel/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (.../parcel/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (.../parcel/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (.../parcel/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (.../parcel/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (.../parcel/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (.../parcel/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (.../parcel/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (.../parcel/node_modules/@babel/traverse/lib/context.js:118:16)
morajabi commented 5 years ago

setting NODE_ENV to production seems to fix the issue.

subhero24 commented 5 years ago

NODE_ENV=production did not resolve it for my parcel build

jouderianjr commented 4 years ago

any way to fix this? I'm facing the same issue here: https://github.com/dillonkearns/elm-graphql/pull/247

The only way to make it work is by removing the minification, but this is not ideal.

trickyc0d3r commented 4 years ago

@Siyfion how did you install realm to use it with parcel? I always get error on react-native

xialvjun commented 4 years ago

Still exists...

jouderianjr commented 4 years ago

@xialvjun Just giving you some context, some time ago I opened an issue about this and basically Parcel 1 is in maintenance mode, so we need to wait until Elm in parcel 2. I'm not sure if is already implemented or not.

Issue

hoangvvo commented 4 years ago

This still happens on v2. It now works in dev (parcel serve) but would result in runtime error in production (The build is still successful).

The title of ths issue should be changed to mention explicitly graphql.