Sam*_*gNY 398 reactjs create-react-app
当我create-react-app my-app
在终端中键入命令时,它似乎可以工作 - 成功下载所有库等。但是在该过程结束时,我收到一条消息,显示template was not provided
.
输入
user@users-MacBook-Pro-2 Desktop% create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
输出
Creating a new React app in /Users/user/Desktop/my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
..... nothing out of the ordinary here .....
? Done in 27.28s.
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
Run Code Online (Sandbox Code Playgroud)
在 package.json 中my-app
:
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0" <-- up-to-date
}
Run Code Online (Sandbox Code Playgroud)
我查看了 CRA更改日志,看起来好像添加了对自定义模板的支持 - 但看起来命令create-react-app my-app
不会改变。
知道这里发生了什么吗?
小智 542
如果您之前已
create-react-app
通过 全局安装npm install -g create-react-app
,我们建议您卸载软件包npm uninstall -g create-react-app
以确保npx
始终使用最新版本。
使用以下任一命令:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
如果npm uninstall -g create-react-app
上述说明不起作用。
键入which create-react-app
以了解其安装位置。我的安装在/usr/bin
文件夹中。然后做sudo rm -rf /usr/bin/create-react-app
。(归功于下面的@v42 评论)
Rob*_*uch 84
1)
npm uninstall -g create-react-app
Run Code Online (Sandbox Code Playgroud)
或者
yarn global remove create-react-app
Run Code Online (Sandbox Code Playgroud)
2)
似乎存在一个错误,即 create-react-app 未正确卸载并使用新命令之一导致:
未提供模板。这可能是因为您使用的是过时版本的 create-react-app。
使用 卸载它后npm uninstall -g create-react-app
,检查您的命令行上是否仍然使用which create-react-app
(Windows: where create-react-app
) “安装”了它。如果它返回一些东西(例如/usr/local/bin/create-react-app),然后rm -rf /usr/local/bin/create-react-app
手动删除。
3)
然后这些方法之一:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
Run Code Online (Sandbox Code Playgroud)
小智 50
虽然已经有很多答案在这里。我想出了 3 个解决方案,当我遇到这种情况时,我一步一步地应用了这些解决方案。
第一步:从官方手册,
如果您之前通过 全局安装了 create-react-app
npm install -g create-react-app
,我们建议您卸载软件包npm uninstall -g create-react-app
以确保 npx 始终使用最新版本。
https://create-react-app.dev/docs/getting-started
您可以在下面使用这些命令:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
第二步(如果第一个不起作用):
有时它可能会保留缓存。然后您可以使用下面给出的这些命令。
npm uninstall -g create-react-app
npm cache clean --force
npm cache verify
yarn create react-app my-app
第三步:(如果这两个不起作用)首先通过 卸载npm uninstall -g create-react-app
,然后检查您是否仍然使用which create-react-app
命令行上的命令“安装”了它。如果你有类似(/usr/local/bin/create-react-app)的东西,那么运行这个rm -rf /usr/local/bin/create-react-app
(文件夹可能会有所不同)手动删除。然后再次通过 npx/npm/yarn 安装它。
注意:我在最后一步成功了。
小智 34
首先通过以下命令全局卸载 create-react-app:
npm uninstall -g create-react-app
Run Code Online (Sandbox Code Playgroud)
然后在您的项目目录中:
npm install create-react-app@latest
Run Code Online (Sandbox Code Playgroud)
最后:
npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
Bak*_*rov 21
将更多内容添加到上述答案中:
使用新版本的create-react-app
,您可以使用自定义模板创建新应用程序。目前可用的两个模板:
用法:
npx create-react-app my-app [--template typescript]
Run Code Online (Sandbox Code Playgroud)
有关最新更改的更多详细信息create-react-app
:
https://github.com/facebook/create-react-app/releases/tag/v3.3.0
小智 19
我也有同样的问题。当我尝试npm init react-app my-app
命令返回相同的消息时
未提供模板。这可能是因为您使用的是过时版本的 create-react-app。
但
yarn create react-app my-app
命令工作正常。
小智 17
npm install -g create-react-app
在你的电脑里 npx create-react-app my-app
Dev*_*mUK 15
首先清除你的 npm 缓存,然后使用 yarn 如下:
npm cache clean --force
npm cache verify
yarn create react-app my-app
我希望这有帮助。
编辑
...在我进一步研究此问题后,您可能想尝试以下操作:
npm uninstall -g create-react-app
yarn global remove create-react-app
which create-react-app
- 如果它返回一些东西(例如 /usr/local/bin/create-react-app),然后执行 rm -rf /usr/local/bin/create-react-app 手动删除。npm cache clean --force
npm cache verify
npx create-react-app@latest
这些步骤应该删除全局安装的 create-react-app 安装,然后手动删除链接到旧的全局安装的 create-react-app 脚本的旧目录。清除 npm 缓存以确保不使用任何旧缓存版本的 create-react-app 是一个好主意。最后,创建与新reactjs的应用程序@latest
,像这样的选择:npx create-react-app@latest
。在使用 npx create-react-app 时没有创建模板的这个问题有很多混乱,如果你按照我上面提到的步骤(1-6)那么我希望你能成功。
ps
如果我想在名为 client 的目录中创建一个 react 应用程序,那么我将在终端中键入以下命令:
npx create-react-app@latest ./client
祝你好运。
小智 13
这两个步骤对我有用
1)使用此命令全局卸载react-app
npm uninstall -g create-react-app
Run Code Online (Sandbox Code Playgroud)
2) 使用此命令在项目文件夹中安装 react-app
npx create-react-app project-name
Run Code Online (Sandbox Code Playgroud)
Gul*_*ibi 10
"如果您之前已经通过 npm install -g create-react-app 全局安装了 create-react-app,我们建议您使用 npm uninstall -g create-react-app 卸载包,以确保 npx 始终使用最新版本"
这在https://create-react-app.dev/docs/getting-started/报告。对我来说,这不起作用。我不得不在全局重新安装 create-react-app。
我解决这个问题的步骤是:
小智 10
在 MacOS 上,所有选项都不适用于我。有效的是以下 3 个步骤:
- 从以下位置删除节点:/usr/local/bin/
然后
- 新安装节点:https : //nodejs.org/en/
然后
- 安装 react:npx create-react-app my-app 关注:https : //create-react-app.dev/
对于 Linux,这对我有用
sudo npm uninstall -g create-react-app
npx create-react-app my-test-app
Run Code Online (Sandbox Code Playgroud)
TLDR:npm uninstall -g create-react-app
使用npx create-react-app app
.
您使用的是create-react-app
使用 npm 全局安装的旧版本。该create-react-app
命令调用此全局包。
您可以通过运行npm outdated -g create-react-app
或create-react-app --version
与npm view create-react-app
.
的版本react-scripts
是最新的这一事实与引导应用程序的包的版本无关 ( create-react-app
),后者获取它使用的包的最新版本(react-scripts
在这种情况下)。
如果要继续使用该create-react-app
命令,则需要使用npm update -g create-react-app
. 请注意,您需要定期执行此操作以使其保持最新状态。您会注意到create-react-app
不建议这样做(在安装日志中注明)。
更好的方法是完全删除全局安装 ( npm uninstall -g create-react-app
) 并改为使用,npx
以便它每次都获取最新版本的包(更多详细信息见npx
下文)。
您应该通过尝试使用create-react-app
以确保“未找到”命令来确认它已被全局卸载。
卸载问题?
您可以使用which create-react-app
. 如果您在卸载它时遇到问题,您的机器上可能有多个 node/npm 版本(来自多次安装,或者因为您使用了 node 版本管理器,例如nvm
)。这是一个单独的问题,我不会在这里解决,但在这个答案中有一些信息。
一个快速的核方法是rm -rf
在which create-react-app
返回的路径上强行移除它 ( ) 。
npx
命令$ NPM_PACKAGE_NAME
无论您在哪个目录中,都将始终使用包的全局安装版本。
$ npx NPM_PACKAGE_NAME
将使用从当前目录搜索到根目录时找到的第一个版本的包:
可以在此答案中找到有关 npx 的更多信息。
npx
与create-react-app
create-react-app
有一些特殊的命令/别名来创建npx
特定于该包 ( yarn create react-app
, npm init react-app
)的 react 应用程序(而不是),但npx create-react-app
与其他包的工作方式相同。
yarn
与npm
全球安装Yarn 将全局安装存储在与 不同的文件夹中npm
,这就是为什么yarn create react-app
可以在不卸载全局 npm 包的情况下立即工作(就 Yarn 而言,该包尚未安装)。
不过,这只是一个临时解决方案,因为您需要记住在使用 Create React App 时始终使用 yarn 而不是 npm。
小智 5
这解决了我的问题
脚步:
1.卸载create-react应用
npm uninstall -g create-react-app
Run Code Online (Sandbox Code Playgroud)
2.现在只需使用
npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
这将自动为 u 创建模板。
这对我有用!
1) npm uninstall -g create-react-app
2) npm install -g create-react-app
3) npx create-react-app app_name
如果您以前
create-react-app
通过 全局安装了任何npm install -g create-react-app
,最好使用卸载它npm uninstall -g create-react-app
这个问题不是这样解决的,问题出在不同的node实例上,尝试全局删除create-react-app,然后从root用户中删除node_modules和package-lock.json
归档时间: |
|
查看次数: |
115561 次 |
最近记录: |