Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 544
Seth Lutske Avatar asked May 11 '26 08:05

Seth Lutske


1 Answers

Try to clear jest cache

jest --clearCache

or

npm run test -- --clearCache
like image 56
Sergiy Seletskyy Avatar answered May 13 '26 02:05

Sergiy Seletskyy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!