当我使用常规的npm或npx命令
时npm -version
或
npx -version
没有错误,但是对于我在使用时的本机项目
npx react-native init testApp
它显示此错误:
does not contain a package.json file in appdata folder
如何解决此错误?
答案 0 :(得分:1)
这是因为您的计算机名称中有空格,除了围绕计算机的命名空间工作外,您还可以尝试将 create-react-app 全局安装为 npm i -g create-react-app
,然后运行再次使用您的 npx create-react-app your-app-name
命令,这为我解决了!
答案 1 :(得分:0)
该错误通常在PC名称包含空格时发生。喜欢
mycomputer name
您应该通过重新定义npm缓存根来解决此问题 尝试:
npm config set cache "C:\Users\mycomputer~1name\AppData\Roaming\npm-cache" --global
在pc名称中注意空格字符,应改用“〜1”
祝你好运
答案 2 :(得分:0)
$ npx create-react-app your project name
答案 3 :(得分:0)
您可以使用
npx create-react-app yourAppName
答案 4 :(得分:0)
更改缓存文件夹。
npm config set cache C:\tmp\nodejs\npm-cache --global