简体   繁体   中英

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?

Try to clear jest cache

jest --clearCache

or

npm run test -- --clearCache

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 babel-preset-react-app@7.0.0 

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 babel-preset-react-app@7.0.0

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

同样的事情发生在我身上,降级到babel-preset-react-app@7.0.0修复了它,根据上面的相同建议。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM