Create-React-App不能创建起始模板

16

我正在按照这些说明的步骤,尝试使用typescript模板创建一个新项目。

npx create-react-app app-ui --template typescript

虽然它安装了所有的节点模块,但它不创建起始项目,也不使用提供的模板。 我会收到这条消息:

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.

我试图按照说明删除cli的全局安装,但那也不起作用:

 npm uninstall -g create-react-app
 up to date in 0.037s
无论我做什么,都无法卸载 cli。发生了什么事?
编辑:
我已经能够在电脑上部分地使用它。
npm remove create-react-app
< p >然后< /p >
npx create-react-app my-app [--template typescript]

我尝试使用括号,虽然模板项目已经存在,但它没有使用typescript。现在cli有些严重的问题。

编辑:

这篇文章 解决了无法卸载 cli 的问题。希望对某些人有所帮助,请为 OP 点赞。

13个回答

17

针对 OP:

你的括号放错了位置。 对于你的情况,文档docs中建议使用:

npx create-react-app my-app --template [template-name]  
或者
npx create-react-app my-app --template typescript

对于其他人:

  1. 卸载(我在Linux/Ubuntu上)

sudo npm uninstall -g create-react-app
  • 然后运行:

    npx create-react-app my-app
    

  • 注意:确保在卸载时删除了所有文件夹/文件。如果您像我一样在Linux设置中访问React文件夹时遇到问题(由于权限),请通过以下方式获得访问权限并删除:

    sudo chown -R $USER /usr/bin/create-react-app
    

    (...然后执行npx命令。)


    1
    移除括号后,TypeScript 模板功能正常了。我不确定为什么我之前加了它们。我猜我只是尝试任何可能让事情工作的方法。谢谢! - Mickers

    11

    我通过sudo npm uninstall -g create-react-app解决了这个问题。

    但是这没有删除create-react-app,所以我不得不检查它位于哪个目录。在终端中,如果你输入:

    which create-react-app

    它会给你一些目录,比如/usr/local/bin/create-react-app,现在执行以下操作:

    rm -rf /usr/local/bin/create-react-app
    

    现在你可以手动移除create-react-app。接下来,你可以使用npx create-react-app my-app来创建React应用程序。


    2
    我正在使用Ubuntu 19.10,这个方法非常有效! - Mooncake

    5
    我遇到了同样的问题。这对我有用(Linux)
    步骤01。
    sudo npm remove create-react-app
    

    步骤02。
    sudo npm uninstall -g create-react-app
    

    步骤 03。
    npx create-react-app my-app --template typescript
    

    我希望这有所帮助。

    这完美地解决了我的问题。谢谢。 - Alexzhang

    0
    我的解决方案与你的有些不同,所以我在这里添加一下,以防有人遇到类似的问题。显然,我使用yarn全局安装了create-react-app,当我运行which create-react-app时可以看到它的路径为.../.config/yarn/global/node_modules/.bin/create-react-app。运行yarn global remove create-react-app删除了这个包,然后我就能够成功地运行npx create-react-app app --template typescript了。

    0
    1. 使用以下命令卸载create-react-app: sudo npm uninstall -g create-react-app

    由于npm不支持全局使用npm模块。

    1. 使用以下命令像往常一样安装create-react-app boiler-plate: npx create-react-app my-app

    它可以正常工作!


    0
    创建 React 启动模板
    1. 运行 npx create-react-app your_app_name 2. 切换到项目目录 cd your_app_name 3. 启动项目 npm start

    0
    即使您运行了 npm uninstall -g create-react-appcreate-react-app 仍可能已安装。您可以通过运行 which create-react-app 进行检查。如果返回路径,则表示 create-react-app 仍已安装。您可以使用 rm -r ${returned path} 删除该模块。之后,运行 npx create-react-app app-ui --template typescript 应该可以无错误或警告地工作。

    0

    当我面对这种情况时,我想出了3个解决方案,逐步应用。

    第一步:从官方手册中获取信息,

    如果您之前通过npm install -g create-react-app全局安装了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安装它。 NB: 我在最后一步成功了。


    0

    对于Windows用户,请按照以下两个步骤进行操作

    npm uninstall -g create-react-app

    然后

    npx create-react-app jamming

    保持更新您的node和npm,使用最新稳定版本


    0

    我在使用Windows命令提示符时遇到了同样的问题,但是后来我尝试在Powershell上执行以下步骤,它就可以工作了。如果仍然无法正常工作,则请以管理员身份运行Powershell。

    npx create-react-app my-app
    cd my-app
    npm start
    

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接