在 VSCode 中使用 npx create-react-app 时出错

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

我对此非常陌生,我必须在 Visual Code 中使用 React 进行家庭作业。我安装了node.js,但是当我尝试运行 npx create-react-app 时。它弹出一个错误,我不知道我需要做什么来修复。我尝试卸载并安装node.js几次,但错误仍然存在。

user@users-MacBook-Air atest % npx create-react-app .
Creating a new React app in /Users/user/Documents/atest.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /Users/user/.npm/_cacache/index-v5/92/81
npm ERR! errno EACCES
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 501:20 "/Users/user/.npm"
npm ERR! A complete log of this run can be found in: /Users/user/.npm/_logs/2024-04-25T09_18_07_410Z-debug-0.log
Aborting installation.
  npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
Deleting atest/ from /Users/user/Documents
Done.
user@users-MacBook-Air atest %  

我尝试更改所有者,但还有另一个问题:我没有密码,当我运行 sudo chown -R 501:20 时,它要求我输入密码...

有人可以帮我解决这个问题吗,谢谢!

我多次安装和卸载node.js 我尝试使用“sudo chown -R 501:20”

reactjs node.js visual-studio-code
1个回答
0
投票

当我遇到缓存问题时,我使用 npm 命令清理缓存:

npm 缓存清理 --force

Sudo 默认有一个密码,您需要指定它才没有密码: sudo密码修改说明

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