【发布时间】:2020-05-27 07:21:03
【问题描述】:
我正在使用
localhost:client davea$ npm -version
6.11.3
并遵循此处的建议 -- Issue with babel-jest dependency when running npm start in a React app ,没有做任何事情来帮助我的情况。我想开始一个完全空白的项目,所以我尝试了
npx create-react-app client
cd client
但是当我尝试启动时,我得到了这个错误
localhost:client davea$ npm start
> client@0.1.0 start /Users/davea/Documents/workspace/chicommons/maps/client
> react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"babel-jest": "^24.9.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:
/Users/davea/Documents/workspace/node_modules/babel-jest (version: 22.4.1)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /Users/davea/Documents/workspace/node_modules/babel-jest is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls babel-jest in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed babel-jest.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/davea/.npm/_logs/2020-02-11T19_49_36_594Z-debug.log
我还应该做些什么来实现这个目标?
【问题讨论】:
-
当您按照您提供的错误消息中列出的步骤修复它时发生了什么?它是否改变了您收到的错误消息或完全相同的情况再次发生?
-
您的意思是“删除 package-lock.json”……然后重新安装?是的,同样的事情也会发生。
-
作为错误状态,我认为很清楚,您在工作区/文件夹中安装了 babel-jest,并且您尝试在工作区/chicommons/maps 子文件夹中安装,并且据说现在有冲突的版本。 npm/yarn 递归地检查 node_modules 目录。你为什么要在现有 npm 模块安装的子文件夹中创建-react-app?为什么不使用干净的新文件夹?
-
是的,运行“sudo rm -rf /Users/davea/Documents/workspace/node_modules”解决了这个问题。
标签: reactjs npm babel-jest npm-start