ReactJS npm start error.项目依赖关系树有问题



Terminal

npm start
> matchstatz@0.1.0 start C:Users7OneDriveDesktopmatchstatztaskmatchstatz
> 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-loader": "8.1.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:
C:Users7node_modulesbabel-loader (version: 8.0.6)
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-loader" 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 C:Users7node_modulesbabel-loader is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls babel-loader in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed babel-loader.
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! matchstatz@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the matchstatz@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!     C:Users7AppDataRoamingnpm-cache_logs2020-06-03T18_01_06_704Z-debug.log

调试日志

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v12.17.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle matchstatz@0.1.0~prestart: matchstatz@0.1.0
6 info lifecycle matchstatz@0.1.0~start: matchstatz@0.1.0
7 verbose lifecycle matchstatz@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle matchstatz@0.1.0~start: PATH: C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin;C:Users7OneDriveDesktopmatchstatztaskmatchstatznode_modules.bin;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program FilesJavajdk-12.0.2bin;C:Program FilesMicrosoft VS Codebin;C:Program Filesdotnet;C:Program FilesGitcmd;C:Program Filesnodejs;C:Users7.windows-build-toolspython27;C:Users7AppDataLocalMicrosoftWindowsApps;C:Users7AppDataLocalGitHubDesktopbin;C:Users7AppDataRoamingnpm
9 verbose lifecycle matchstatz@0.1.0~start: CWD: C:Users7OneDriveDesktopmatchstatztaskmatchstatz
10 silly lifecycle matchstatz@0.1.0~start: Args: [ '/d /s /c', 'react-scripts start' ]
11 silly lifecycle matchstatz@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle matchstatz@0.1.0~start: Failed to exec start script
13 verbose stack Error: matchstatz@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecycleindex.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclelibspawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid matchstatz@0.1.0
15 verbose cwd C:Users7OneDriveDesktopmatchstatztaskmatchstatz
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
18 verbose node v12.17.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error matchstatz@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the matchstatz@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

**在上面的详细信息中,我已经使用 npx create-react-app appname 创建了 reactjs 应用程序,但在使用 cd 命令进入目录后,如果我给 npm start 意味着我会收到这种错误。我已在此处粘贴了调试日志和终端错误。并将错误详细信息获取为"项目依赖项树可能存在问题。 这可能不是Create React App中的错误,而是您需要在本地修复的问题。

你应该删除/Users/nameOfYourComputer/node_modules,因为这似乎是你的根目录,你通常不应该在那里node_modules。

已经有一天了,我试图弄清楚,我尝试了上述说明,但直到我在 reddit 中找到这个解决方案才一无所获。

不久前,我遇到了同样的问题,我遵循了下面提到的相同步骤。

要修复依赖项树,请尝试按确切顺序执行以下步骤:

  1. 删除项目文件夹中的package-lock.json(不是package.json!(和/或yarn.lock。
  2. 删除项目文件夹中的node_modules。
  3. 从项目文件夹的 package.json 文件中的依赖项和/或 devDependencies 中删除"babel-loader"。
  4. 运行 npm install 或 yarn,具体取决于您使用的包管理器。

最新更新