使用create-react-app时出现错误 - ENOENT

4
新的Node和React用户在这里。我正在按照React教程进行学习,但在我的Windows 10机器上遇到了问题:
C:\Users\Wout>create-react-app my-app

Creating a new React app in C:\Users\Wout\my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! path C:\Users\Wout\my-app\node_modules\abab
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Wout\my-app\node_modules\abab' -> 'C:\Users\Wout\my-app\node_modules\.abab.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Wout\AppData\Roaming\npm-cache\_logs\2018-03-14T15_21_11_867Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-app / from C:\Users\Wout
Done.

到目前为止我尝试了以下方法:

  • 重新安装Node.js(v8.10.0,npm 5.6.0)
  • 禁用Adobe Creative Cloud同步和相关进程(这些正在产生node.exe进程)
  • 以管理员身份运行CMD
  • 在VS Code Powershell中运行命令
  • 在执行命令之前关闭Visual Studio Code
  • 使用npx运行命令
  • 多次重启系统
  • 从用户文件夹以及其他驱动器运行命令
  • 运行TypeScript版本:create-react-app my-app --scripts-version=react-scripts-ts

对我来说,这一切都很奇怪,因为在Mac OS X上执行该命令没有问题。我似乎也找不到其他有同样问题的人。

值得一提的是,它总是在“finalizing abab”软件包步骤之后停止。

我安装了XAMPP并运行了Apache和MySQL服务,不知道这是否与此有关。我认为不会,因为我甚至还没有运行应用程序,而且服务器已经在3000端口上运行了。


ENOENT表示缺少文件。 C:\ Users \ Wout \ my-app \ node_modules \ abab在那里吗?在运行create-react-app my-app之前,请尝试安装此单个软件包。这可以通过命令npm install abab来实现。 - ilmirons
7个回答

9
不要使用create-react-app my-app,而是像这样运行npx create-react-app my-app。如果错误仍然存在,请运行'npm install -g npm'。然后再次运行npx create-react-app my-app

6

我最终通过关闭尽可能多的额外进程来解决了这个问题。会尝试找出哪个进程与命令有冲突。

编辑:叮咚!是MalwareBytes! “实时保护30天试用版”在更新后重新启动,它正在破坏文件系统。


3
刚开始学习React编码时遇到了同样的错误。
  1. 安装了VS Code
  2. 安装了Node.js
  3. 运行npx create-react-app MyApp,但是出现了错误
  4. 进入Windows(C:)/Users/UserName/AppData/Roaming
  5. 创建一个新文件夹并将其命名为npm
  6. 回到VS Code,命令应该可以运行(实际上会要求安装额外的包)

在第4步中,如果你看不到AppData文件夹,你的文件资源管理器需要进行设置: 查看/显示/隐藏的项目


它对我有用。谢谢 :) - undefined

0

尝试从项目目录中运行命令... 对我有用。 例如,我从项目目录的父级运行了该命令: reactApp/helloworld 改为从helloworld目录运行...


0
如果您刚刚安装了create-react-app命令,请尝试从新的终端(重新打开另一个选项卡)中运行该命令。

0

我也刚安装了 MalWareBytes,遇到了同样的错误。我尝试以管理员身份从 CLI 运行 create-react-app,在它运行时我看到了你的解决方案,于是在安装过程中关闭了 MalWareBytes。

这样做起作用了,但我不知道是因为我以管理员身份运行,还是因为我关闭了 MalWareBytes。

但对于任何遇到此问题的人,您也可以尝试以管理员权限运行命令提示符/PowerShell。


0
尝试运行命令 'npm fund',然后再尝试重新运行命令 'npm create-react-app my-app'。
这对我来说有效。

1
您的回答可以通过提供更多支持信息来改进。请[编辑]以添加更多详细信息,例如引用或文档,以便其他人可以确认您的回答是否正确。您可以在帮助中心找到有关如何撰写良好回答的更多信息。 - Community

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