问题描述
我刚刚更新了我的 npm 并删除了一些无用的包,但由于某种原因,我在尝试运行此命令时仍然遇到一些奇怪的问题
kalebamarante$ npm init create-react-app kalebcryptoexchange-app
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/create-create-react-app - Not found
npm ERR! 404
npm ERR! 404 'create-create-react-app@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball,folder,http url,or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kalebamarante/.npm/_logs/2021-03-09T00_18_58_939Z-debug.log
KALEBS-MacBook-Pro:~ kalebamarante$ npx create-react-app kalebcryptoexchange-app
You are running `create-react-app` 4.0.1,which is behind the latest release (4.0.3).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
npm ERR! code 1
npm ERR! path /Users/kalebamarante
npm ERR! command Failed
npm ERR! command sh -c create-react-app kalebcryptoexchange-app
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kalebamarante/.npm/_logs/2021-03-09T00_20_01_995Z-debug.log
KALEBS-MacBook-Pro:~ kalebamarante$ sh -c create-react-app kalebcryptoexchange-app
kalebcryptoexchange-app: create-react-app: command not found
解决方法
你应该试试 npx 而不是 npm init。
npx create-react-app kalebcryptoexchange-app
。
你应该使用 npx 而不是 npm。
npx create-react-app your-app
现在为什么会这样?
当您使用 npm 命令时,它会为您获取节点包。即您可能已经使用 npm 全局安装了名为“create-react-app”的包。现在要执行该包,您必须使用 npx 命令。
您的错误日志显示了这一行,
npm ERR! 404 'create-create-react-app@latest' is not in the npm registry.
因为您正在尝试获取一个包,而不是使用 create-react-app 创建它。
简而言之,npm 下载包,npx 执行包。