graphql-js: [Bug] (Create React App) Issues with resolving an .mjs file instead of an .js file leading to test failures
Running tests on a local project get’s the following errors since the publish of 0.13.1
● Test suite failed to run
Cannot find module 'graphql/language/parser' from 'graphql-tag.umd.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:194:17)
at node_modules/graphql-tag/lib/graphql-tag.umd.js:7:14
at node_modules/graphql-tag/lib/graphql-tag.umd.js:2:65
at Object.<anonymous> (node_modules/graphql-tag/lib/graphql-tag.umd.js:5:2)
FAIL
● Test suite failed to run
Cannot find module 'graphql/language/printer' from 'bundle.umd.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:194:17)
at Object.<anonymous>.Object.setPrototypeOf.__proto__ (node_modules/apollo-link/lib/bundle.umd.js:2:138)
at Object.<anonymous> (node_modules/apollo-link/lib/bundle.umd.js:5:2)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 17
- Comments: 40 (12 by maintainers)
Commits related to this issue
- fix: see https://github.com/graphql/graphql-js/issues/1248 — committed to ryota-murakami/clock-up by ryota-murakami 6 years ago
- Downgrade graphql to avoid test bug Running into this issue: https://github.com/graphql/graphql-js/issues/1248. Need to wait for this PR to get merged: https://github.com/facebook/create-react-app/p... — committed to cityofaustin/ctxfloods by luqmaan 6 years ago
- Upgrade frontend dependencies (#144) * Upgrade frontend dependencies Major changes: - react 16 => 16.2 - mapbox-gl-style-spec 9 => 11 - react-apollo 1 => 2 - required some code changes to ... — committed to cityofaustin/ctxfloods by deleted user 6 years ago
- fix(gql): https://github.com/graphql/graphql-js/issues/1248#issuecomment-377549258 — committed to ryota-murakami/clock-up by ryota-murakami 6 years ago
- Add resolutions to pkg.json in TS example This is a way to guarantee that users install graphql@13.0 instead of 13.2 (which is broken) https://github.com/graphql/graphql-js/issues/1248 — committed to jaredpalmer/react-apollo by jaredpalmer 6 years ago
- Fix production build (#265) * Fix production build The production build failing was the result of a bug related to an older version react-scripts not playing nice with the latest version of graphq... — committed to livepeer/livepeer-monorepo by adamsoffer 6 years ago
- Fix production build (#265) * Fix production build The production build failing was the result of a bug related to an older version react-scripts not playing nice with the latest version of graphq... — committed to livepeer/studio by adamsoffer 6 years ago
- Fix production build (#265) * Fix production build The production build failing was the result of a bug related to an older version react-scripts not playing nice with the latest version of graphq... — committed to livepeer/studio by adamsoffer 6 years ago
- Fix production build (#265) * Fix production build The production build failing was the result of a bug related to an older version react-scripts not playing nice with the latest version of graphq... — committed to livepeer/subgraph by adamsoffer 6 years ago
Broken here, as well.
Having a similar issue with this version on my Jest test setup. Previous version
0.13.0is fine.Yes, I’m using Jest (technically, Create React App, which comes with Jest built-in) and react-apollo.
If your project is built with Create React App and not ejected,
react-scripts@1.1.2should fix this. Here is how to upgrade:https://github.com/facebook/create-react-app/releases/tag/v1.1.2
Otherwise you can apply a similar fix yourself in your project config. Cheers!
Also, I can confirm that forcing graphql back to version 0.13.0 resolves the issue. ie. in the repo above add
"graphql": "0.13.0",topackage.jsonunderdependeciesand re-install.Just an update:
Sorry to keep everyone waiting on this issue. I’ve confirmed that an issue in the default Jest configuration for create-react-app is the root issue and still have https://github.com/facebook/create-react-app/pull/4085 open to attempt to fix it. Please visit that issue if you’re having issues with GraphQL and CRA together.
As a mitigation strategy, you can
ejectto gain access to the test configuration to apply the change yourself:yarn ejectpackage.jsonmoduleFileExtensionssection of thejestsection:I hope this helps unblock some of you in the meantime
@stevensacks Me too exactly same stack.
@leebyron i’ll comment some infomation by my personal project …
↓ circleci build faild log with this issue. https://circleci.com/gh/ryota-murakami/clock-up/478
↓ entire repository of commit when facing this issue. https://github.com/ryota-murakami/clock-up/tree/bb76468b017ffa85058b13223ea9b2fb2f96522b
↓ faild specific jest test file https://github.com/ryota-murakami/clock-up/blob/bb76468b017ffa85058b13223ea9b2fb2f96522b/src/App/Control/ClockinButton.test.js
I’ve opened https://github.com/facebook/create-react-app/pull/4085 to solve this issue. I’ll keep this issue open to track progress.
0.13.0 works fine, changing the package.json to
"graphql": "0.13.0"solves the problem for nowAs an update - the fix to create-react-app was merged, however still awaiting a point release which will hopefully happen soon.
I think I’ve found the source issue, this arrives when using
create-react-app(which usesreact-scripts)react-scriptslooks for.mjsfiles when resolving files ahead of.jsfiles and regardless of the use ofrequire()vsimportor what transforms are in place.https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/scripts/utils/createJestConfig.js#L56
This was introduced in https://github.com/facebook/create-react-app/pull/3239 / https://github.com/facebook/create-react-app/commit/5c8000f300a003e9bd8aee70c0796fa4e20b34f0
Hi there, I’m also seeing this issue. As with the other reporters, this is a Create React App application testing with the default configuration.
See this repo for an example with the failing test: https://github.com/mikehazell/graphql-jest-issue This is a Create React App with the only change being to add
graphql-tagas a dependency and import it in the main App.js file.Run
yarn test srcto see the error.I’m having a similar problem with this version, here’s the traceback:
Text version:
@leebyron did you try actually running the app? It compiles successfully but throws the
TypeError: parse is not a functionwhen you actually run it. Here’s the stack trace that create-react-app displays in the browser when I try to run it:This was with graphql 0.13.2 and graphql-tag 2.8.0
“0.13.1 is broken” isn’t a great title - the version is working correctly outside of this particular issue and we need to narrow down what’s going on.
The cause, as I see it is that when the file “parser” is being required, that this resolves to “parser.mjs” instead of “parser.js” despite the mjs import syntax not being understood.
Node’s module resolution will always resolve “parser” to “parser.js” (unless from another mjs file when using --experimental-modules), so there must be a different module resolver causing this issue.
The reason I assumed Jest was a direction to investigate is that Jest uses a custom module resolver and almost all reports in this issue are failing Jest tests.
Has anyone been able to create a test repo which consistently exhibits this issue? I’ve still yet to reproduce it. Once I have my hands on a consistent reproduction then I can help to debug the root cause.