【问题标题】:How can I change npm version while using create-react-app如何在使用 create-react-app 时更改 npm 版本
【发布时间】:2019-05-26 18:23:42
【问题描述】:

我正在尝试在命令行中运行 create-react-app,但我不断收到以下消息:

“您使用的是 npm 2.15.12,因此该项目将使用旧的不受支持的工具版本进行增强。”

我跑了

sudo npm install npm@latest -g

确保我拥有最新版本的 npm(我还尝试了“sudo npm install -g npm”)。当我跑步时

npm -v

输出是“6.4.1”

我在 create-react-app 过程中遇到了一些错误,但应用程序本身似乎工作正常,“npm start”工作正常,所有文件似乎都在正确的位置,但我不想要以后会遇到更多错误。

经过几个小时的搜索,我找不到使用错误版本的 npm 的 create-react-app 的任何其他问题。有没有办法在使用 create-react-app 时更改正在使用的 npm 版本?

下面的隐藏代码 sn-p 列出了我在 create-react-app 期间遇到的错误。我觉得他们可能是由于使用了过时的 npm 版本。

node-pre-gyp ERR! Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v67-darwin-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for fsevents@1.0.17 and node@11.0.0 (node-v67 ABI) (falling back to source compile with node-gyp) 
node-pre-gyp ERR! Tried to download(undefined): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v67-darwin-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for fsevents@1.0.17 and node@11.0.0 (node-v67 ABI) (falling back to source compile with node-gyp) 

gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/myuser/node_modules/npm/node_modules/node-gyp/lib/build.js:285:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 17.4.0
 
gyp ERR! node -v v11.0.0
gyp ERR! node-gyp -v v3.6.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute

【问题讨论】:

    标签: node.js reactjs npm create-react-app


    【解决方案1】:

    解决了。我相信我有一些额外的节点文件浮动(可能来自我没有正确执行的安装)。我决定完全删除 nvm/node/npm 并重新安装(我在 Mac 上)。

    为了删除 nvm 和 node,我删除了 /usr 中的所有 node 和 node_package 文件(有很多关于在哪里可以找到节点文件和文件夹的教程)。我按照指南进行操作,但也有一些例外。我有一个简单命名为“n”的文件夹,其中包含一些节点文件(然后我将其删除),然后必须显示我的隐藏文件才能在 /users/userName 中找到一个“.nvm”文件夹。我删除了“.nvm”文件夹,终于能够完全摆脱 nvm、node 和 npm。

    在我全新安装 nvm 和节点后(我必须重新制作 .nvm 文件夹才能使 nvm 安装脚本正常工作),create-react-app 命令正常工作。

    【讨论】:

      【解决方案2】:

      你需要使用这个来更新你的 npm 版本:

      npm install -g npm
      

      请注意,此命令将删除您当前版本的 npm。确保使用

      sudo npm install -g npm 
      

      如果在 Mac 上。

      【讨论】:

      • 感谢迪瓦卡的回复!我尝试使用 sudo npm install -g npm(我在 Mac 上),它运行时没有任何问题。当我运行npm -v 时,我仍然得到“6.4.1”,运行npx create-react-app 时得到相同的“你正在使用 npm 2.15.12”。让 npx create-react-app 使用正确的 npm 版本还有其他想法吗?
      猜你喜欢
      • 2021-12-02
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      • 2018-08-18
      相关资源
      最近更新 更多