Ubuntu 22.04执行npx create-react-app报错,求解决方案
React项目创建失败(ENOENT错误)解决办法
问题场景
在Ubuntu 22.04.1 LTS系统中执行npx create-react-app .创建React项目时触发如下错误,此前该命令一直正常运行,近期突然失效:
(base) akj@JammyJellyfish:~/Desktop/Social-Media-App/client$ npx create-react-app . npm WARN config tmp This setting is no longer used. npm stores temporary files in a special npm WARN config location in the cache, and they are managed by npm WARN config [`cacache`](http://npm.im/cacache). npm ERR! code ENOENT npm ERR! syscall lstat npm ERR! path /home/akj/.var/app/com.visualstudio.code/data/node_modules npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, lstat '/home/akj/.var/app/com.visualstudio.code/data/node_modules' 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! /home/akj/.npm/_logs/2023-01-09T14_52_48_118Z-debug-0.log (base) akj@JammyJellyfish:~/Desktop/Social-Media-App/client$
解决办法
- 手动创建缺失目录:执行以下命令创建npm找不到的路径,之后重新运行创建命令
mkdir -p /home/akj/.var/app/com.visualstudio.code/data/node_modules - 重置npm全局路径配置:执行命令清除可能错误的前缀设置,避免npm指向无效路径
npm config delete prefix - 清理npm缓存:强制清除缓存,解决缓存文件损坏或路径关联错误
npm cache clean --force - 直接调用最新版create-react-app:绕过本地可能存在的依赖问题,强制使用官方最新包
npx --no-install create-react-app@latest . - 切换终端执行命令:如果使用VS Code内置终端,尝试在系统原生终端运行命令,排查Flatpak版VS Code的文件访问权限限制
内容的提问来源于stack exchange,提问作者Abhinav
相关产品推荐
相关产品推荐

