卸载create-react-app时出现的问题

28

我正在运行npm uninstall create-react-app,它返回

npm WARN saveError ENOENT: no such file or directory, open '/Users/me/Documents/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/me/Documents/package.json'
npm WARN Documents No description
npm WARN Documents No repository field.
npm WARN Documents No README data
npm WARN Documents No license field.
我想更新我的create-react-app版本,但显然他们不再支持全局安装。当我第一次安装CRA时(一段时间之前),它是全局安装的。现在,我正在尝试更新它,但遇到问题。我运行了npm update create-react-app,但是我的终端只是闪烁了一秒钟就返回了提示符。因此,我决定彻底卸载create-react-app并重新安装它,但现在我遇到了上述警告/问题。
你有什么想法出了什么问题吗?
编辑:
当我运行 npm i create-react-app 时,它也会抛出上述的WARN,但它还说
+ create-react-app@3.3.0 // <---
added 1 package and audited 578 packages in 1.787s

然而,当我再次运行命令 create-react-app --version 时,它显示为3.2.0

编辑2:

我已经多次运行了npm i -g create-react-app,但是它会抛出以下错误:

Michaels-MacBook-Pro:Documents me$ npm i -g create-react-app
npm ERR! code EEXIST
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/create-react-app/index.js
npm ERR! dest /usr/local/bin/create-react-app
npm ERR! errno -17
npm ERR! EEXIST: file already exists, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'
npm ERR! File exists: /usr/local/bin/create-react-app
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2019-12-23T08_07_29_158Z-debug.log


你需要使用全局标志 (-g),这样就可以运行命令:npm uninstall -g create-react-app。同样,你也需要在安装或更新时使用相同的标志。 - noitse
运行该命令后,我得到了响应 up to date in 0.031s。然而,如果我紧接着运行 create-react-app --version,它会显示 3.2.0 - Mike K
你正在运行哪个操作系统? - PatMan10
我正在使用MacOS Mojave。 - Mike K
15个回答

107

全局卸载了create-react-app后,我仍然收到了一个错误提示,说我的create-react-app版本过旧。以下是解决方法:

在这之后:

sudo npm uninstall -g create-react-app

运行

npx clear-npx-cache

然后尝试在正确的工作目录中重新安装create-react-app

npx create-react-app my-app

1
我一直收到这样的消息,即使我已经运行了全局卸载,也不应该安装CRA。我只需要执行clear-npx-cache命令。为此点赞。 - Mark Fraser
当我尝试使用clear-npx-cache时,出现错误TypeError: fs_1.rmSync不是一个函数 - aurelia
4
npx clear-npx-cache有效。 - rlib

27

要完全卸载它,请尝试运行

sudo npm uninstall -g create-react-app

有时候这个命令可能无法完全删除包。如果是这样,请检查包所在的目录:

which create-react-app

它会给你类似 /usr/local/bin/create-react-app 的目录。只需手动删除它即可。

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

现在您可以通过以下方式安装create-react-app:

npm install -g create-react-app

但是,从 v3.3.0 开始不建议全局安装它。所以只需使用:

npx create-react-app <project_name>

7

只需重新运行以下命令即可安装它。

sudo npm i -g create-react-app

我个人使用NCU (https://www.npmjs.com/package/npm-check-updates)来更新所有的node相关内容。它可以全局使用也可以在每个项目中使用。


4

对于 Windows 10 用户, 请前往 C:\Users\[用户名]\AppData\Roaming\npm 然后删除 create-react-app 文件。


直到我做了以下操作,这里提供的任何方法都无法在Windows 10上使用ReactJS在Visual Studio中运行。如果遇到问题,我还删除了“npm-cache”。如有需要,我会在此发布问题。 - mdkb

4

进一步使用Windows 10

虽然Dhruv的答案为我解决了这个问题(找到并删除create-react-app,然后重新安装),但我仍然有一些问题无法在我的Windows 10系统中找到create-react-app

我试图找到我的全局安装(where create-react-app对我没有任何结果),据我所知,它从未安装过。但是,通过使用Win + X键选择“Windows PowerShell(管理员)”,然后导航到我想要的工作目录,我随后可以执行npx create-react-app my-test-app,并创建一个可用的React目录。

在Windows 10中,似乎使用提升的cmd提示符是成功使用npx create-react-app my-test-app的方法。我不确定原因是什么。因为以前它对我来说至少在正常的cmd提示符下工作。


3

对于Windows系统

我尝试了npm uninstall -g create-react-app但没有成功。

我按照以下步骤操作,成功了:

  1. 使用管理员权限打开cmd命令提示符:输入where create-react-app,它应该在系统文件的yarn目录下。找到路径并删除这两个文件。
  2. 进入工作目录,我的情况中是一个在documents里面的文件夹。运行npx create-react-app my-test-app

这将创建一个名为my-test-app的新文件夹,你可以按照React App网站上的其余说明进行操作。

进入新建的文件夹,运行yarn start


1

我之前也遇到了同样的问题。尝试了很多解决方案,但都没有成功。

最后,我在Youtube上找到了一个视频,帮助我解决了这个问题。

视频链接: create-react-app error

我使用的命令是:

npm uninstall -g create-react-app ; npm i -g npm@latest ; npm cache clean -f

注意:根据您的节点版本,您可能需要在此处使用&&代替;


0
对于那些在运行npm uninstall -g create-react-app后仍收到删除任何全局安装的消息,而清除缓存不起作用的人,我发现先全局安装,然后再全局卸载有帮助。因此,执行以下步骤:
npm install -g create-react-app
npm uninstall -g create-react-app

我运行了npx clear-npx-cache,以防万一,它起作用了。我猜新的安装覆盖了无法清理的剩余文件。另外,我应该提到,我使用的是Windows 10和PowerShell以管理员权限运行;我不确定是否需要管理员权限。


1
每次卸载时,我没有收到错误信息,而是看到了一条消息,显示已更新,审核了1个软件包,用时217毫秒,未发现漏洞。我尝试了您的方法,它起作用了! :) - necixy

0
我的解决方法是运行 npm install create-react-app@latest,这样就可以更新而不需要删除和重新安装(这对我也没有用)。

0

我的问题是缺少单词模板

只有下面的命令才对我有效:

npx create-react-app my-app --template typescript

更多内容请点击这里


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