create-react-app: 2.1.4 Update cause "Cannot find module '/Users/.../node_modules/react-scripts/node_modules/@babel/runtime/helpers/interopRequireDefault' from 'setupTests.ts'"
Environment
System:
OS: macOS 10.14.2
CPU: x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 11.6.0 - ~/.nvm/versions/node/v11.6.0/bin/node
Yarn: 1.12.3 - ~/.nvm/versions/node/v11.6.0/bin/yarn
npm: 6.5.0-next.0 - ~/.nvm/versions/node/v11.6.0/bin/npm
Browsers:
Chrome: 72.0.3626.96
Firefox: 64.0
Safari: 12.0.2
npmPackages:
react: ^16.8.1 => 16.8.1
react-dom: ^16.8.1 => 16.8.1
react-scripts: ^2.1.4 => 2.1.4
npmGlobalPackages:
create-react-app: Not Found
Steps to Reproduce
Starting from my project with react-scripts: 2.1.3
,
yarn
yarn test
workingyarn add react-scripts@2.1.4
yarn test
workingyarn-deduplicate
what is this
Introducing these modifications in the yarn.lock
-"@babel/plugin-transform-destructuring@7.3.2":
+"@babel/plugin-transform-destructuring@7.3.2", "@babel/plugin-transform-destructuring@^7.0.0", "@babel/plugin-transform-destructuring@^7.2.0":
version "7.3.2"
-"@babel/plugin-transform-destructuring@^7.0.0", "@babel/plugin-transform-destructuring@^7.2.0":
- version "7.2.0"
-
-ajv@^6.1.0, ajv@^6.5.3, ajv@^6.5.5:
- version "6.7.0"
-
-ajv@^6.9.1:
+ajv@^6.1.0, ajv@^6.5.3, ajv@^6.5.5, ajv@^6.9.1:
version "6.9.1"
-autoprefixer@^9.3.1:
- version "9.4.6"
-
-autoprefixer@^9.4.2:
+autoprefixer@^9.3.1, autoprefixer@^9.4.2:
version "9.4.7"
-caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000884, caniuse-lite@^1.0.30000929:
- version "1.0.30000929"
-
-caniuse-lite@^1.0.30000918, caniuse-lite@^1.0.30000932:
+caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000884, caniuse-lite@^1.0.30000918, caniuse-lite@^1.0.30000929, caniuse-lite@^1.0.30000932:
version "1.0.30000936"
-core-js@2.6.4:
+core-js@2.6.4, core-js@^2.4.0, core-js@^2.4.1, core-js@^2.5.0, core-js@^2.5.7:
version "2.6.4"
-core-js@^2.4.0, core-js@^2.4.1, core-js@^2.5.0, core-js@^2.5.7:
- version "2.6.3"
-
-postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.13, postcss@^7.0.2, postcss@^7.0.5:
- version "7.0.13"
-
-postcss@^7.0.14, postcss@^7.0.6:
+postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.2, postcss@^7.0.5, postcss@^7.0.6:
version "7.0.14"
-react-error-overlay@^5.1.0:
- version "5.1.2"
-
-react-error-overlay@^5.1.3:
+react-error-overlay@^5.1.0, react-error-overlay@^5.1.3:
version "5.1.3"
-resolve@1.10.0, resolve@^1.9.0:
+resolve@1.10.0, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.2.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1, resolve@^1.9.0:
version "1.10.0"
-resolve@^1.1.6, resolve@^1.1.7, resolve@^1.2.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1:
- version "1.9.0"
-
yarn
yarn test
not working anymore
Test suite failed to run
Cannot find module '/Users/.../node_modules/react-scripts/node_modules/@babel/runtime/helpers/interopRequireDefault' from 'setupTests.ts'
1 | import { configure } from 'enzyme';
2 | import Adapter from 'enzyme-adapter-react-16';
> 3 | import 'jest-extended';
| ^
4 | import 'jest-localstorage-mock';
5 | import { getSnapshotDiffSerializer, toMatchDiffSnapshot } from 'snapshot-diff';
6 |
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
at Object.<anonymous> (src/setupTests.ts:3:30)
If needed I’ll try to make a reproductible demo. My actual project is for work (and not open-source…).
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 39
- Comments: 57 (6 by maintainers)
Commits related to this issue
- Fix babel interop test errors As seen in https://github.com/facebook/create-react-app/issues/6398#issuecomment-470556290 — committed to cheshire137/competiwatch-desktop by cheshire137 5 years ago
- Fix security vulnerabilities, lock babel package I ran `npm audit fix`. Then the tests failed. So I had to do `npm i babel-preset-react-app@7.0.0` based on [this issue](https://github.com/facebook/cr... — committed to douglasnaphas/madliberationjs by douglasnaphas 4 years ago
For me, upgrading to 2.1.8 did not help. What did help though, is running tests with --clearCache:
Hope this helps. See https://jestjs.io/docs/en/cli.html#clearcache for details
I was able to work around this issue with:
The latest version as of this writing is
7.0.1
. It appears that something related to #6393 is causing this issue.Relevant commits:
FYI @ianschmitz. I’m not sure if this is related to your work, but your name popped up.
Thanks, this worked for me after an upgrade from node 10.x to 12.x.
In my case, it was
npm run test -- --clearCache
thennpm run test
We’re still actively investigating this, and trying to get a fix out as soon as possible. Hopefully everyone has been able to use the workarounds posted above in the meantime.
Chiming in that I’m running into this as well. Curious to see the fix. Thanks for the workaround in the interim, everyone!
I hade the same issue but I’m not using yarn. So I did
react-scripts test --clearCache
once and then removed the flag.The problems shows up after upgrading react scripts to version 3.3.1
This worked for me not sure why
I don’t use storybook and have this problem as well:
Fresh install has not solved the problem for me. I had to do
npm i babel-preset-react-app@7.0.0
to run tests now.Hi all, I’ve had this report from some colleagues too. I’m not sure what’s causing it, we’re looking into it.
This worked for us on our debian machine! Jest was working when logged as root, but not as our service user.
Adding
@babel/runtime
to dependencies in our app worked for us. Hopefully this is just a temporary solution.Work around for tests in CRA I used to make this work is runt the test script with transformIgnorePatterns in package.json
"test": "react-scripts test --transformIgnorePatterns '/node_modules/'"
Still broken for me with 2.1.8.
Before:
(failing)
Steps to fix, inspired by comments above but the order matters.
First step: add the following to your
packages.json
:Second step:
% yarn add -D babel-preset-react-app@7.0.0
Then it should be good.
After:
@bugzpodder understood. I also can’t repro this on a fresh CRA install. I think this issue may be related to the testing toolchain, as my error output looks very similar to @VincentLanglet’s:
I have the same issue with the module babel-preset-react-app since I updated to react-script@2.1.4
the module babel-preset-react-app doesn’t have a
node_modules/
folder anymore. I have to fix it the same way you fix your problem. I have to add manually the entirenode_modules/@babel
insidebabel-preset-react-app
For me error gone after doing
cp -R my-project copy
or clonning project into directory with a different name. ¯\(ツ)/¯I have to manually add
@babel/runtime
insidereact-scripts/node-modules
to fix this…I’m seeing a similar error with react-scripts@3.0.1. Every Jest test fails to import Adapter from ‘enzyme-adapter-react-16’:
npm ls
shows that only 9.0.1 version of babel-preset-react-app is installed:Installing babel-preset-react-app@7.0.0 as suggested above fixes the issue and all tests can run fine.
Deleting a lock file should not introduce breaking changes. It will only update your dependencies within the range specified in your
package.json
file, as well as your indirect dependencies.Weird… I ran the following command:
Maybe that helps.
@mrmckeb I only have one copy fo babel-preset-react-app I use yarn and don’t have @storybook installed anywhere.
=> Found “babel-preset-react-app@7.0.1” info Reasons this module exists
Downgrading to babel-preset-react-app@7.0.0 helps, but only because in node_modules/babel-preset-react-app/node_modules/@babel/runtime exists. Removing the node_modules inside babel-preset-react-app causes the same error.
Alternatively adding “nohoist”: [ “**/babel-preset-react-app/@babel/runtime” ] and sticking to babel-preset-react-app 7.0.1 works as well.
Thank you so much, it worked for me !
We are no longer seeing this issue after upgrading to react-scripts@3.4.0 and removing babel-preset-react-app@7.0.0 from devDependencies.
This worked for me. Delete node_modules and running
yarn install
did not fix the issue.Thanks! It worked for me
God bless ya! Works!
Nevertheless, the problem still exists in
"react-scripts": "3.1.1",
… It started to happen to me once I usedyarn upgrade-interactive
for some minor updates…One note, when I run tests through cli, then they run properly. The problem occurred only when I run the tests through IntelliJ.
Thanks.
It will update all the library of the project. Introducing a lot of breaking change. A lock file is not made to be deleted.
@Ciaran0 this is unrelated, please try react-scripts@2.1.5 to resolve.
FYI, I don’t know how but it works now and
npm ls babel-preset-react-app
returnsSeems like something wrong between dependencies and
yarn
not doing always the same thing…OK, one more question - is everyone here using
@storybook/react
? It looks like it might be because that package has a dependency on"babel-preset-react-app": "^6.1.0"
.When I remove
@storybook/react
, the problem goes away. When I add it back, but use Yarnresolutions
to force"babel-preset-react-app": "7.0.1"
, the problem is also gone.Can anyone else confirm this?
If this is not the case, can you please run the below and post the results here?
Sorry I only use yarn on this project because of workspaces. I tried a fresh install of create-react-app but didn’t run into this issue.
I had a workaround where I told yarn not to hoist “**/babel-preset-react-app/@babel/runtime” It might be because previously two different versions of @babel/runtime were used so it was not hoisted when installed, but now that the versions match the package is hoisted to the top level node modules…