簡體   English   中英

開玩笑 - 找不到模塊'.../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault'

[英]Jest - Cannot find module '.../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault'

我正在嘗試在我的 CI/CD 機器上運行我的項目測試。 它們是在我所有的環境中運行良好一段時間的開玩笑測試。 我正在通過軟件包更新,並且在此過程中的某個地方,我開始遇到問題。 我看到每個測試都失敗了,因為如果出現此錯誤:

 ● 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)

這發生在 Debian Ubuntu-16 linux 實例上,節點為 14.16.3 和 npm 8.1.0。

沒有發生在我的本地機器上。 我的本地機器可以正常運行這些測試。 我的本地是 mac Catalina 10.15.7,我嘗試過節點 14 和 16 的版本,以及 npm 7 和 8,都沒有問題。 我確實閱讀了 Unable to resolve module @babel/runtime/helpers/interopRequireDefault以及許多其他相關問題,但沒有解決方案有幫助。 我努力了

  • npm install @babel/runtime
  • npm install babel-preset-react-app
  • 添加"nohoist": ["**/babel-preset-react-app/@babel/runtime"]到 package.json
  • 卸載並重新安裝所有軟件包幾次

有點令人困惑的是,這些測試在我的筆記本電腦上運行良好,上面有我嘗試過的所有變體,但在我的 CI/CD 實例上失敗了,上面有我嘗試過的所有變體。

我能做些什么來調試這個? 盡管如上所述嘗試了最佳答案和建議,為什么這個問題仍然存在?

嘗試清除笑話緩存

jest --clearCache

或者

npm run test -- --clearCache

我遇到了同樣的問題,但相反:它可以在我的 Azure 管道上運行,但在本地失敗。 運行此命令后,我讓所有測試在兩種環境中都成功運行:

npm i babel-preset-react-app@7.0.0 

基於這個問題: https ://github.com/facebook/create-react-app/issues/6398#issuecomment-462475835

發布它的用戶 ( jeremyckahn ) 說:

我能夠通過以下方式解決此問題:

npm i babel-preset-react-app@7.0.0

撰寫本文時的最新版本是 7.0.1。 似乎與 #6393 相關的東西導致了這個問題。

相關提交:

b02f181#diff-5a51074922f8107dc611b7e125130e7e

b7e0158#diff-5a51074922f8107dc611b7e125130e7e

同樣的事情發生在我身上,降級到babel-preset-react-app@7.0.0修復了它,根據上面的相同建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM