Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile issue with Rollup #1293

Closed
acoreyj opened this issue Mar 20, 2018 · 10 comments
Closed

Compile issue with Rollup #1293

acoreyj opened this issue Mar 20, 2018 · 10 comments

Comments

@acoreyj
Copy link

acoreyj commented Mar 20, 2018

Looks like the way index.js handles it's exports rolllup can't find it

{ Error: 'GraphQLObjectType' is not exported by node_modules/graphql/type/index.js
at error (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:168:15)
at Module.error (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:17602:9)
at handleMissingExport (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:17863:12)
at /Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:19512:56
at Array.reduce (native)
at Graph.handleMissingExport (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:19511:27)
at Module.traceExport (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:17720:28)
at Module.trace (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:17695:43)
at ModuleScope.findVariable (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:14890:28)
at Scope.findVariable (/Users/Corey/Documents/workspace/mkr/node_modules/rollup/dist/rollup.js:11840:68)
code: 'MISSING_EXPORT',
url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module',
pos: 1383,
loc:
{ file: '/Users/Corey/Documents/workspace/mkr/node_modules/graphql/index.mjs',
line: 41,
column: 19 },
frame: '39: export { GraphQLSchema,\n40: // Definitions\n41: GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, GraphQLDirective,\n ^\n42: // "Enum" of Type Kinds\n43: TypeKind,' }

[ ERROR ] bundling: node_modules/graphql/index.mjs, line: 41
'GraphQLObjectType' is not exported by node_modules/graphql/type/index.js

 L40:  // Definitions
 L41:  GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputOb
 L42:  // "Enum" of Type Kinds
@acoreyj
Copy link
Author

acoreyj commented Mar 22, 2018

Just a follow up removing the mjs files fixes it, may be a similar issue to problems Webpack is having

@LennyPenny
Copy link

Removing the mjs files?
Is there a better way to work around this automatically?

@acoreyj
Copy link
Author

acoreyj commented Mar 23, 2018

I don't know, I'm also having issues with graphql-tools rollup. I'm working with Stencil (https://github.com/ionic-team/stencil) so I don't have access to the typescript and rollup configs to try and get it to work.

I haven't setup a basic repo to replicate yet but I guess that would be the next step.

@gaberudy
Copy link

Having this issue with rollup as well.

It looks like with the new graphql/index.mjs the sub-directories are not properly defining their exports in all cases.

graphql/validation/index.js properly defines exports.VariablesInAllowedPositionRule = exports.VariablesDefaultValueAllowedRule = .... = undefined;, but the other sub-directoriesindex.js files do not.

My commonjs plugin looks like this to get around it (will try to get a pull request together if my emacs macro-foo is up for it):

    commonjs({
      namedExports: {
        // left-hand side can be an absolute path, a path
        // relative to the current directory, or the name
        // of a module in node_modules
         '../node_modules/graphql/execution/index.js': ['execute', 'defaultFieldResolver', 'responsePathAsArray', 'getDirectiveValues'],
         '../node_modules/graphql/utilities/index.js': ['getIntrospectionQuery', 'introspectionQuery', 'getOperationAST', 'introspectionFromSchema', 'buildClientSchema', 'buildASTSchema', 'buildSchema', 'getDescription', 'extendSchema', 'lexicographicSortSchema', 'printSchema', 'printIntrospectionSchema', 'printType', 'typeFromAST', 'valueFromAST', 'valueFromASTUntyped', 'astFromValue', 'TypeInfo', 'coerceValue', 'isValidJSValue', 'isValidLiteralValue', 'concatAST', 'separateOperations', 'isEqualType', 'isTypeSubTypeOf', 'doTypesOverlap', 'assertValidName', 'isValidNameError', 'findBreakingChanges', 'findDangerousChanges', 'BreakingChangeType', 'DangerousChangeType', 'findDeprecatedUsages'],
          '../node_modules/graphql/error/index.js': ['GraphQLError', 'formatError', 'printError'],
          '../node_modules/graphql/language/index.js': ['Source', 'getLocation', 'parse', 'parseValue', 'parseType', 'print', 'visit', 'visitInParallel', 'visitWithTypeInfo', 'getVisitFn', 'Kind', 'TokenKind', 'DirectiveLocation', 'BREAK'],
          '../node_modules/graphql/subscription/index.js': ['subscribe', 'createSourceEventStream'],
          '../node_modules/graphql/type/index.js': ['GraphQLSchema', 'GraphQLScalarType', 'GraphQLObjectType', 'GraphQLInterfaceType', 'GraphQLUnionType', 'GraphQLEnumType', 'GraphQLInputObjectType', 'GraphQLList', 'GraphQLNonNull', 'GraphQLDirective', 'TypeKind', 'specifiedScalarTypes', 'GraphQLInt', 'GraphQLFloat', 'GraphQLString', 'GraphQLBoolean', 'GraphQLID', 'specifiedDirectives', 'GraphQLIncludeDirective', 'GraphQLSkipDirective', 'GraphQLDeprecatedDirective', 'SchemaMetaFieldDef', 'TypeMetaFieldDef', 'TypeNameMetaFieldDef', 'introspectionTypes', 'DEFAULT_DEPRECATION_REASON', '__Schema', '__Directive', '__DirectiveLocation', '__Type', '__Field', '__InputValue', '__EnumValue', '__TypeKind', 'isSchema', 'isDirective', 'isType', 'isScalarType', 'isObjectType', 'isInterfaceType', 'isUnionType', 'isEnumType', 'isInputObjectType', 'isListType', 'isNonNullType', 'isInputType', 'isOutputType', 'isLeafType', 'isCompositeType', 'isAbstractType', 'isWrappingType', 'isNullableType', 'isNamedType', 'isSpecifiedScalarType', 'isIntrospectionType', 'isSpecifiedDirective', 'assertType', 'assertScalarType', 'assertObjectType', 'assertInterfaceType', 'assertUnionType', 'assertEnumType', 'assertInputObjectType', 'assertListType', 'assertNonNullType', 'assertInputType', 'assertOutputType', 'assertLeafType', 'assertCompositeType', 'assertAbstractType', 'assertWrappingType', 'assertNullableType', 'assertNamedType', 'getNullableType', 'getNamedType', 'validateSchema', 'assertValidSchema', 'Source', 'getLocation', 'parse', 'parseValue', 'parseType', 'print', 'visit', 'visitInParallel', 'visitWithTypeInfo', 'getVisitFn', 'Kind', 'TokenKind', 'DirectiveLocation', 'BREAK', 'execute', 'defaultFieldResolver', 'responsePathAsArray', 'getDirectiveValues', 'subscribe', 'createSourceEventStream', 'GraphQLError', 'formatError', 'printError', 'getIntrospectionQuery', 'introspectionQuery', 'getOperationAST', 'introspectionFromSchema', 'buildClientSchema', 'buildASTSchema', 'buildSchema', 'getDescription', 'extendSchema', 'lexicographicSortSchema', 'printSchema', 'printIntrospectionSchema', 'printType', 'typeFromAST', 'valueFromAST', 'valueFromASTUntyped', 'astFromValue', 'TypeInfo', 'coerceValue', 'isValidJSValue', 'isValidLiteralValue', 'concatAST', 'separateOperations', 'isEqualType', 'isTypeSubTypeOf', 'doTypesOverlap', 'assertValidName', 'isValidNameError', 'findBreakingChanges', 'findDangerousChanges', 'BreakingChangeType', 'DangerousChangeType', 'findDeprecatedUsages']
      }
    }),

@leebyron
Copy link
Contributor

leebyron commented Mar 29, 2018

I'd love to see a complete rollup.config.js file encountering this issue - my guess is that rollup-plugin-node-resolve is to blame here.

I arrived at a repro by doing the following:

mkdir rollup-test
cd rollup-test
npm init -y rollup-test
echo "import {parse} from 'graphql'; console.log(parse('{test}'));" > index.js
echo "import resolve from 'rollup-plugin-node-resolve';\
export default {\
  input: 'index.js',\
  output: { file: 'bundle.js', format: 'iife' },\
  plugins: [resolve()]\
}" > rollup.config.js
./node_modules/.bin/rollup -c

This fails with:

index.js → bundle.js...
[!] Error: 'parse' is not exported by node_modules/graphql/language/index.js

Which implies that rollup is inadvertently looking at the .js file when it requires ES Module syntax and cannot understand the Common JS format. To fix this, rollup-plugin-node-resolve supports expanding the extensions:

-  plugins: [resolve()]
+  plugins: [
+    resolve({
+      extensions: ['.mjs', '.js', '.json']
+    })
+  ]

Now running rollup -c works as expected.

Ideally rollup-plugin-node-resolve would use this extension by default

leebyron added a commit to leebyron/rollup-plugin-node-resolve that referenced this issue Mar 29, 2018
Since rollup prefers ESM formatted modules, it should look for node's new .mjs file extension before looking for .js files by default. This offers support for deployed modules intended to be used in node's ESM mode.

Folks can work around this today by manually supplying the `extensions` option, however it would be great if this worked by default.

Note that looking for `.mjs` before `.js` is important for rollup which prefers ESM, however the `resolve` dependency should not use the same order by default since it is used in many other tools which do not yet support ESM or would not expect it by default.

Encountered this as the root cause behind graphql/graphql-js#1293
@leebyron
Copy link
Contributor

The good news is that you can fix this yourself with very little effort - just modify your rollup.config.js file to include the '.mjs' extension. I've opened a PR (rollup/rollup-plugin-node-resolve#151) to enable this by default in Rollup to hopefully make this easier in the future

@gaberudy
Copy link

@leebyron first of all, thanks for digging into this. It looks like more of a rollup issue than a graphql, so I appreciate it you taking it to the mattresses and finding a solution.

For some reason, my rollup config edited like yours to prefer mjs picks up the index.mjs file at the root of the package, but then resolves the sub-modules with index.js running into the export issue again:

Gabes-MacBook-Air-2:apiserver grudy$ yarn run rollup
yarn run v1.3.2
$ rollup -c rollup.config.js

src/embedded_server.ts → dist/chakra_embedded_server.js...
[!] Error: 'execute' is not exported by ../node_modules/graphql/execution/index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
../node_modules/graphql/index.mjs (73:9)
71: 
72: // Execute GraphQL queries.
73: export { execute, defaultFieldResolver, responsePathAsArray, getDirectiveValues } from './execution';
             ^
74: 
75: export { subscribe, createSourceEventStream } from './subscription';

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Your pull request to rollup I hope gets accepted and fixes the secondary (recursive) module resolution to use index.mjs and then life is roses and daisies again.

@IvanGoncharov
Copy link
Member

Lee PR was merged but AFAIK not released yet so I don't see anything else we can do in graphql-js to help with this issue.

@eljenso
Copy link

eljenso commented Oct 25, 2018

Changes from PR are in current release of rollup-plugin-node-resolve (v3.4.0) but I still get this error:

[!] Error: 'print' is not exported by node_modules/graphql/language/index.js
https://rollupjs.org/guide/en#error-name-is-not-exported-by-module-
node_modules/graphql/index.mjs (51:0)
49: export { Source, getLocation, // Parse
50: parse, parseValue, parseType, // Print
51: print, // Visit
    ^
52: visit, visitInParallel, visitWithTypeInfo, getVisitFn, Kind, TokenKind, DirectiveLocation, BREAK, // Predicates
53: isDefinitionNode, isExecutableDefinitionNode, isSelectionNode, isValueNode, isTypeNode, isTypeSystemDefinitionNode, isTypeDefinitionNode, isTypeSystemExtensionNode, isTypeExtensionNode } from './language';
Error: 'print' is not exported by node_modules/graphql/language/index.js

Error does go away if I define a very long commonjs({namedExports: {...} }).

@ersinakinci
Copy link

I ran into this problem, as well. Adding '.mjs' to my extensions didn't work until I added it to the beginning of my extensions list. So instead of

// Nice and alphabetical...but wrong
resolve({ extensions: ['.es', '.es6', '.js', '.jsx', '.mjs', '.ts', '.tsx'] })

I did

resolve({ extensions: ['.mjs', '.es', '.es6', '.js', '.jsx', '.ts', '.tsx'] })

and only then did the error go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants