【问题标题】:different node version conflicts while npm installnpm install 时不同的节点版本冲突
【发布时间】:2023-03-23 06:56:01
【问题描述】:

每次我想做npx create-react-app my_app时都会遇到这个问题

yarn add v1.15.2
[1/4] ????  Resolving packages...
[2/4] ????  Fetching packages...
error eslint@6.2.1: The engine "node" is incompatible with this module. 
Expected version "^8.10.0 || ^10.13.0 || >=11.10.1". Got "8.3.0"

但是当我使用 nvm 和 bash 检查我的版本时,这就是我得到的

$ node -v
v8.16.1
$ npm -v
6.4.1
$ nvm ls
nvm ls
->      v8.16.1
        v9.10.1
        v12.0.0
         system
default -> node (-> v12.0.0)
node -> stable (-> v12.0.0) (default)
stable -> 12.0 (-> v12.0.0) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.1
lts/dubnium -> v10.16.3 (-> N/A)

我真的不明白为什么它在执行 npx 命令时说我得到了节点 8.3.0 并且该版本无处出现

可能是因为我前段时间用brew安装过node,可能和nvm设置冲突?


当我分别发出 npm install -g create-react-appcreate-react-app my-app 时它可以工作,因为这是 facebook 推荐的旧节点版本

$ npm install -g create-react-app
+ create-react-app@3.1.1
added 91 packages from 45 contributors in 4.491s

$ create-react-app trainin
yarn add v1.15.2
[1/4] ????  Resolving packages...
[2/4] ????  Fetching packages...
[3/4] ????  Linking dependencies...
warning "react-scripts > @typescript-eslint/eslint-plugin@1.13.0" has incorrect peer dependency "eslint@^5.0.0".
warning "react-scripts > @typescript-eslint/parser@1.13.0" has incorrect peer dependency "eslint@^5.0.0".
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] ????  Building fresh packages...
success Saved lockfile.
success Saved 7 new dependencies.
info Direct dependencies
├─ react-dom@16.9.0
├─ react-scripts@3.1.1
└─ react@16.9.0
info All dependencies
├─ eslint-config-react-app@5.0.1
├─ react-dev-utils@9.0.3
├─ react-dom@16.9.0
├─ react-error-overlay@6.0.1
├─ react-scripts@3.1.1
├─ react@16.9.0
└─ scheduler@0.15.0
✨  Done in 15.45s.

【问题讨论】:

  • 用 nvm 修复你的 nodejs 版本

标签: node.js bash npm homebrew nvm


【解决方案1】:

你最好卸载brew安装的版本,并设置与所需npx兼容的默认版本。

【讨论】:

  • brew说node是yarn需要的,正常吗?说我可能会尝试 --ignore-dependencies 但我不想破坏任何东西:/
  • 当然,yarn 是 nodejs 的包管理器。我的意思是你应该使用一种工具来管理你的 nodejs、brew 或 nvm。
【解决方案2】:

您可以使用n 包,它允许您在多个节点版本之间切换

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 2022-06-22
    • 2016-04-12
    相关资源
    最近更新 更多