当我运行“npm install”时,我遇到了我不明白的 npm 问题

Posted

技术标签:

【中文标题】当我运行“npm install”时,我遇到了我不明白的 npm 问题【英文标题】:I am having npm issues I do not understand when I run `npm install` 【发布时间】:2021-08-02 04:08:46 【问题描述】:

当我运行npm install 时,我收到以下错误,我不知道如何解决它。我尝试深入研究该错误日志以解决这些依赖关系,但都无济于事。我将不胜感激任何解决此问题的线索。这是我的 React 第一个代码。感谢期待!

错误日志

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: @babel/core@7.2.2
npm ERR! node_modules/@babel/core
npm ERR!   @babel/core@"7.2.2" from react-scripts@2.1.8
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"^2.1.3" from the root project
npm ERR!     peer react-scripts@">=2.1.3" from react-app-rewired@2.1.8
npm ERR!     node_modules/react-app-rewired
npm ERR!       react-app-rewired@"^2.1.0" from the root project
npm ERR!   @babel/core@"^7.1.6" from @svgr/webpack@4.1.0
npm ERR!   node_modules/@svgr/webpack
npm ERR!     @svgr/webpack@"4.1.0" from react-scripts@2.1.8
npm ERR!     node_modules/react-scripts
npm ERR!       react-scripts@"^2.1.3" from the root project
npm ERR!       1 more (react-app-rewired)
npm ERR!   8 more (babel-core, babel-loader, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @babel/core@"^7.13.0" from @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.13.12
npm ERR! node_modules/@babel/preset-env/node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining
npm ERR!   @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@"^7.13.12" from @babel/preset-env@7.14.1
npm ERR!   node_modules/@babel/preset-env
npm ERR!     @babel/preset-env@"^7.1.6" from @svgr/webpack@4.1.0
npm ERR!     node_modules/@svgr/webpack
npm ERR!       @svgr/webpack@"4.1.0" from react-scripts@2.1.8
npm ERR!       node_modules/react-scripts
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/tiwa/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tiwa/.npm/_logs/2021-05-11T18_39_17_361Z-debug.log

package.json


  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": 
    "@material-ui/core": "^4.0.0",
    "eslint": "^6.0.1",
    "ipfs-api": "^26.1.2",
    "json-loader": "^0.5.7",
    "node-sass": "^4.11.0",
    "react": "^16.8.6",
    "react-app-rewired": "^2.1.0",
    "react-bootstrap": "^1.0.0-beta.5",
    "react-dom": "^16.8.6",
    "react-router-dom": "^5.0.0",
    "react-scripts": "^2.1.3",
    "react-toggle": "^4.0.2",
    "rimble-ui": "^0.7.0",
    "styled-components": "^4.1.3",
    "web3": "1.0.0-beta.37",
    "zeppelin-solidity-hot-loader": "^1.2.3"
  ,
  "scripts": 
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  ,
  "eslintConfig": 
    "extends": "react-app"
  ,
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": 

npm 版本

7.0.8

节点版本

v15.2.1

日志文件

GNU nano 2.0.6                                                 
File: /Users/tiwa/.npm/_logs/2021-05-12T10_58_57_849Z-debug.log                                                                                                          

0 verbose cli [
0 verbose cli   '/Users/tiwa/.asdf/installs/nodejs/15.2.1/bin/node',
0 verbose cli   '/Users/tiwa/.asdf/installs/nodejs/15.2.1/bin/npm',
0 verbose cli   'run',
0 verbose cli   'client'
0 verbose cli ]
1 info using npm@7.0.8
2 info using node@v15.2.1
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/Users/tiwa/.asdf/installs/nodejs/15.2.1/lib/node_modules/npm/npmrc Completed in 2ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Users/tiwa/WebstormProjects/nft/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/tiwa/.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/Users/tiwa/.asdf/installs/nodejs/15.2.1/.npm/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 3ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 13ms
19 verbose npm-session ed61a70477c00f22
20 timing npm:load Completed in 23ms
21 timing command:run-script Completed in 34358ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (/Users/tiwa/.asdf/installs/nodejs/15.2.1/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack     at ChildProcess.emit (node:events:329:20)
22 verbose stack     at maybeClose (node:internal/child_process:1055:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
23 verbose pkgid NFT-based-photo-marketplace@1.0.0
24 verbose cwd /Users/tiwa/WebstormProjects/nft
25 verbose Darwin 20.3.0
26 verbose argv "/Users/tiwa/.asdf/installs/nodejs/15.2.1/bin/node" "/Users/tiwa/.asdf/installs/nodejs/15.2.1/bin/npm" "run" "client"
27 verbose node v15.2.1
28 verbose npm  v7.0.8
29 error code 1
30 error path /Users/tiwa/WebstormProjects/nft
31 error command failed
32 error command sh -c cd client && npm run start

【问题讨论】:

可以分享一下你正在使用的node和npm版本吗? 这能回答你的问题吗? What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case? 没有解决问题 为什么只是安装依赖项就这么困难 【参考方案1】:

您是否尝试过删除node_modules/package-lock.js 然后运行npm install 命令?

【讨论】:

*package-lock.json【参考方案2】:

当大多数 React 项目仍将其声明为可选时,npm 7 需要安装对等依赖项。

您可以使用npm i --legacy-peer-deps 安装或在您的.npmrc 中设置:

npm set config legacy-peer-deps=true

【讨论】:

【参考方案3】:

您确定,您在正确的文件夹中执行 npm install 吗?首先 cd 进入终端中需要安装的正确文件夹,然后运行以下命令 -

npm ci

【讨论】:

为什么要运行 CI 安装?该命令应仅用于持续集成服务。 @LoganDevine 自动删除以前的 node_modules 并进行全新的全新安装。如果 node_modules 已经存在,它将在 npm ci 开始安装之前自动删除。 但是过时的包锁会出错;通常你会做rm -rf node_modules &amp;&amp; npm i【参考方案4】:

一般来说,我发现在出现错误时,yarn 提供的信息比 npm 更好。您能否分享一个指向 /Users/tiwa/.npm/_logs/2021-05-11T18_39_17_361Z-debug.log 的(要点)链接?

【讨论】:

以上是关于当我运行“npm install”时,我遇到了我不明白的 npm 问题的主要内容,如果未能解决你的问题,请参考以下文章

npm install 遇到问题

npm install使用node-pre-grp和node-grp失败

我在运行 npm install 时遇到问题

来自终端的 npm install 错误

当我在 docker 上执行 npm install 时出现问题

在 node-gyp 重建时挂在 npm install 上的厨师客户端