'Jest - Cannot find module '.../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault'
I am trying to run my project's tests on my CI/CD machines. They are jest tests that have been running fine for some time on all my environments. I am going through package updates, and somewhere along the way, I began having issues. I see that every test is failing because if this error:
● Test suite failed to run
Cannot find module '/cicduser/myproject/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault' from 'src/setupTests.ts'
1 | /*
2 | * Filename: setupTests.ts
> 3 | * Classification: UNCLASSIFIED
| ^
at Resolver.resolveModule (node_modules/jest-runtime/node_modules/jest-resolve/build/index.js:306:11)
at Object.<anonymous> (src/setupTests.ts:3:30)
This is happening on a Debian Ubuntu-16 linux instance, with node 14.16.3 and npm 8.1.0.
This is not happening my local machine. My local machine runs these tests just fine. My local is a mac Catalina 10.15.7, and I've tried versions of node 14 and 16, as well as npm 7 and 8, and no issues. I did read Unable to resolve module @babel/runtime/helpers/interopRequireDefault
, as well as a number of other related questions, but no solution is helping. I have tried
npm install @babel/runtime
npm install babel-preset-react-app
- adding
"nohoist": ["**/babel-preset-react-app/@babel/runtime"]
to package.json - uninstalling and reinstalling all packages a few times over with various variations of this
Its a little befuddling that the tests work fine on my laptop, with all variations of what I've tried above, and fail on my CI/CD instance, with all variations of what Ive tried above.
What can I do to debug this? Why would this issue persist, despite trying the best answers and suggestions as described above?
Solution 1:[1]
I was having the same issue but opposite: it would work on my Azure pipeline but fail locally. I got all tests to run successfully in both environments after running this:
npm i [email protected]
Based on this issue: https://github.com/facebook/create-react-app/issues/6398#issuecomment-462475835
The user ( jeremyckahn ) who posted it said this:
I was able to work around this issue with:
npm i [email protected]
The latest version as of this writing is 7.0.1. It appears that something related to #6393 is causing this issue.
Relevant commits:
b02f181#diff-5a51074922f8107dc611b7e125130e7e
b7e0158#diff-5a51074922f8107dc611b7e125130e7e
Solution 2:[2]
The same was happening to me and downgrading to [email protected]
fixed it, per the same suggestion above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | LCIII |
Solution 2 | Tyler2P |