创建 React 应用程序 - 构建在 Netlify 上一直失败但在本地工作
Create React App - Build keeps failing on Netlify but works locally
10:52:56 PM: There might be a problem with the project dependency tree.
10:52:56 PM: It is likely not a bug in Create React App, but something you need to fix locally.
10:52:56 PM: The react-scripts package provided by Create React App requires a dependency:
10:52:56 PM: "babel-jest": "23.6.0"
10:52:56 PM: Don't try to install it manually: your package manager does it automatically.
10:52:56 PM: However, a different version of babel-jest was detected higher up in the tree:
10:52:56 PM: /opt/build/repo/node_modules/babel-jest (version: 24.7.1)
10:52:56 PM: Manually installing incompatible versions is known to cause hard-to-debug issues.
10:52:56 PM: If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
10:52:56 PM: That will permanently disable this message but you might encounter other issues.
10:52:56 PM: To fix the dependency tree, try following the steps below in the exact order:
10:52:56 PM: 1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
10:52:56 PM: 2. Delete node_modules in your project folder.
10:52:56 PM: 3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
10:52:56 PM: 4. Run npm install or yarn, depending on the package manager you use.
10:52:56 PM: In most cases, this should be enough to fix the problem.
10:52:56 PM: If this has not helped, there are a few other things you can try:
10:52:56 PM: 5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
10:52:56 PM: This may help because npm has known issues with package hoisting which may get resolved in future versions.
10:52:56 PM: 6. Check if /opt/build/repo/node_modules/babel-jest is outside your project directory.
10:52:56 PM: For example, you might have accidentally installed something in your home folder.
10:52:56 PM: 7. Try running npm ls babel-jest in your project folder.
10:52:56 PM: This will tell you which other package (apart from the expected react-scripts) installed babel-jest.
10:52:56 PM: If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
10:52:56 PM: That would permanently disable this preflight check in case you want to proceed anyway.
10:52:56 PM: P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
所以我最近向我的应用程序推送了一个新版本并出现了上述错误,与 babel-jest 有关。这在我的package.json里没有,一定是对等依赖什么的
该构建在本地运行良好,我已通过删除 node_modules 和包 -lock.json 进行确认,并且所有安装和运行都很好。
当我推送到 master 时,netlify 记录了这个错误并且不会继续。
因此,为我解决问题的是在 package-lock.json
中搜索 babel-jest
。然后我将该版本添加到我的 package.json
中的决议条目中,如下所示:
"resolutions": {
"babel-jest": "23.6.0"
}
这解决了问题,我的应用程序在 Netlify 上正确发布。
我知道这个问题有点老了,答案已经选好了,但上面的答案对 me.So 不起作用,我是如何解决我的问题的
将 package-lock.json 放入 .gitignore 文件,但如果您已经将它上传到 github 而没有提及它到 .gitignore 文件,则将其删除来自 git 缓存(本地回购)
git rm -r --cached package-lock.json
git add .
git commit -m 'Remove package-lock.json'
git push origin master
在你的 netlify 站点转到站点设置->构建和部署->环境并将以下内容放入环境变量中
SKIP_PREFLIGHT_CHECK=true
如果您的 netlify 构建假设警告为错误,请将以下内容放入构建设置->构建命令
CI=false npm run build
10:52:56 PM: There might be a problem with the project dependency tree.
10:52:56 PM: It is likely not a bug in Create React App, but something you need to fix locally.
10:52:56 PM: The react-scripts package provided by Create React App requires a dependency:
10:52:56 PM: "babel-jest": "23.6.0"
10:52:56 PM: Don't try to install it manually: your package manager does it automatically.
10:52:56 PM: However, a different version of babel-jest was detected higher up in the tree:
10:52:56 PM: /opt/build/repo/node_modules/babel-jest (version: 24.7.1)
10:52:56 PM: Manually installing incompatible versions is known to cause hard-to-debug issues.
10:52:56 PM: If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
10:52:56 PM: That will permanently disable this message but you might encounter other issues.
10:52:56 PM: To fix the dependency tree, try following the steps below in the exact order:
10:52:56 PM: 1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
10:52:56 PM: 2. Delete node_modules in your project folder.
10:52:56 PM: 3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
10:52:56 PM: 4. Run npm install or yarn, depending on the package manager you use.
10:52:56 PM: In most cases, this should be enough to fix the problem.
10:52:56 PM: If this has not helped, there are a few other things you can try:
10:52:56 PM: 5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
10:52:56 PM: This may help because npm has known issues with package hoisting which may get resolved in future versions.
10:52:56 PM: 6. Check if /opt/build/repo/node_modules/babel-jest is outside your project directory.
10:52:56 PM: For example, you might have accidentally installed something in your home folder.
10:52:56 PM: 7. Try running npm ls babel-jest in your project folder.
10:52:56 PM: This will tell you which other package (apart from the expected react-scripts) installed babel-jest.
10:52:56 PM: If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
10:52:56 PM: That would permanently disable this preflight check in case you want to proceed anyway.
10:52:56 PM: P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
所以我最近向我的应用程序推送了一个新版本并出现了上述错误,与 babel-jest 有关。这在我的package.json里没有,一定是对等依赖什么的
该构建在本地运行良好,我已通过删除 node_modules 和包 -lock.json 进行确认,并且所有安装和运行都很好。
当我推送到 master 时,netlify 记录了这个错误并且不会继续。
因此,为我解决问题的是在 package-lock.json
中搜索 babel-jest
。然后我将该版本添加到我的 package.json
中的决议条目中,如下所示:
"resolutions": {
"babel-jest": "23.6.0"
}
这解决了问题,我的应用程序在 Netlify 上正确发布。
我知道这个问题有点老了,答案已经选好了,但上面的答案对 me.So 不起作用,我是如何解决我的问题的
将 package-lock.json 放入 .gitignore 文件,但如果您已经将它上传到 github 而没有提及它到 .gitignore 文件,则将其删除来自 git 缓存(本地回购)
git rm -r --cached package-lock.json
git add .
git commit -m 'Remove package-lock.json'
git push origin master
在你的 netlify 站点转到站点设置->构建和部署->环境并将以下内容放入环境变量中
SKIP_PREFLIGHT_CHECK=true
如果您的 netlify 构建假设警告为错误,请将以下内容放入构建设置->构建命令
CI=false npm run build