如何在使用 create-react-app 时更改 npm 版本

How can I change npm version while using create-react-app

我正在尝试 运行 在命令行中创建-react-app,但我不断收到此消息:

"You are using npm 2.15.12 so the project will be boostrapped with an old unsupported version of tools."

我运行

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 版本?

下面隐藏的代码片段列出了我在 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

您需要使用此更新您的 npm 版本:

npm install -g npm

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

sudo npm install -g npm 

如果 Mac.

已解决。我相信我周围有一些额外的节点文件(可能来自我没有正确安装的文件)。我决定完全删除 nvm/node/npm 并重新安装(我在 mac)。

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

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