小编典典

在React应用中运行npm start时出现babel-jest依赖问题

reactjs

我正在做的是运行create-react-app并进入该应用程序,然后尝试运行npm/yarn start。我得到以下错误/输出/日志。我已经完成了所有建议的步骤。唯一有效的方法是在我的.env中将SKIP_PREFLIGHT_CHECK =
true作为Yarn和npm的最后选择。我最近更新到Mojave,如果人们有类似的经历,则必须重新安装Xcode。

如果图像不够,请在下面粘贴输出。

非常感谢您的提前帮助…杰森

控制台截图 屏幕截图

Last login: Tue Oct 30 16:30:24 on ttys002
TheLAB11:~ jasonspiller$ cd repos/react-express-graphql-app/
TheLAB11:react-express-graphql-app jasonspiller$ npm start

> [email protected] start /Users/jasonspiller/repos/react-express-graphql-app
> 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": "23.6.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/jasonspiller/node_modules/babel-jest (version: 23.4.2)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If 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/jasonspiller/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! [email protected] start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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/jasonspiller/.npm/_logs/2018-10-30T23_09_42_358Z-debug.log

阅读 652

收藏
2020-07-22

共1个答案

小编典典

我只是有同样的问题。由于某种原因,该软件包最终出现node_modules在我的主目录中的某个目录中。这也给了我与jest包裹完全相同的错误。

我不确定解决此问题的 正确 方法,npm uninstall -g babel-jest并且yarn global remove babel- jest不做任何事情。

我通过吹走导致问题的文件夹来修复它: bash rm -rf ~/node_modules/babel-jest ~/node_modules/jest

知道这些软件包是如何结束的,以及摆脱它们的正确方法,将是非常棒的,但是目前,仅删除文件夹就足以使CRA dev服务器运行,而无需跳过预检检查。

2020-07-22