在 Jenkins 中,React 应用程序构建在 Docker 中失败,但在本地失败

React app build fails in Docker in Jenkins, but not locally

在我的本地机器上,npm run build 工作正常。在我通过 Jenkins 启动的 Docker 图像上,我遇到了类似

的问题
Cannot find module: 'file-saver'. Make sure this package is installed.

You can install this package by running: npm install file-saver.

FAIL src/core/App.test.js
  ● Test suite failed to run

    Cannot find module 'surface-nets' from 'vtext.js'

在我的本地机器上,我清除了 npm 缓存 (npm cache clean -f),删除了 node_modules/,并重新安装了 (npm i)。我什至使用 npm updatenpm-check-updates 包来更新所有内容。我安装了所有对等依赖项。我的本地副本应该和 Docker 中的副本一样干净。在 Jenkinsfile 中,我输入了 npm list,它显示了 surface-netsfile-saver 以及我所有的其他包。我还放了 ls node_modules/,我可以看到包文件夹在那里。我已将 Docker 文件减少到只有 1 行:FROM node:current.

为什么安装模块时提示“找不到模块”?

这个问题的根本原因仍然未知,但我确实发现存储库已损坏。我最终擦除整个远程仓库并 git init-ing 一个新的,然后推送到那个。我认为腐败是导致这里手头问题的原因。