设置 React js 项目时出错

问题描述 投票:0回答:1

我是 React JS 新手,并尝试通过命令行设置 React JS 项目,但它抛出了如下错误:

npx create-react-app my-react-app

npm ERR! code ENOENT

npm ERR! syscall lstat

npm ERR! path /usr/local/Cellar/node/21.2.0/lib

npm ERR! errno -2

npm ERR! enoent ENOENT: no such file or directory, lstat '/usr/local/Cellar/node/21.2.0/lib'

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: /Users/ritesh/.npm/_logs/2023-12-03T06_59_38_055Z-debug-0.log

之前这个命令足以创建一个 React 项目设置,但现在它不再起作用了。我尝试创建一个名为

my-react-app
的空白文件夹,但它仍然抛出相同的错误。

reactjs create-react-app
1个回答
0
投票

上次我看到有人遇到同样的问题时,即使他们重新安装了节点,他们的 C: 驱动器中也没有 npm 文件夹。所以,首先通过这个命令检查npm的路径:

npm config get prefix

它会显示npm的路径,如果没有,则大多数npm都存在于该路径中:

C:\Users\your_computer_name\AppData\Roaming\npm

检查Roaming目录下是否有npm文件夹,如果没有则创建一个。然后运行 create-react-app 命令。 我希望这能解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.