【问题标题】:npx create-react-app myapp error "\AppData\Roaming\npm-cache\_npx\19748" does not contain a package.json file in appdata foldernpx create-react-app myapp 错误“\AppData\Roaming\npm-cache\_npx\19748”在 appdata 文件夹中不包含 package.json 文件
【发布时间】:2021-01-06 18:20:06
【问题描述】:

操作系统:Windows
为了使用 npx 创建反应应用程序,我编写了以下命令:

npx create-react-app myapp

它显示了这个错误:

npm ERR! Could not install from "myusername\AppData\Roaming\npm-cache\_npx\19748" as it does not contain a package.json file.

我该如何解决?

【问题讨论】:

  • 已经有关于这个的帖子了,例如:github.com/facebook/create-react-app/issues/4058 难道他们没有帮助吗?
  • 亲爱的@Jayce444我已经尝试了答案中描述的方法,它对我有用,请检查,在github上他们建议使用npm全局安装它,但我想使用npx安装它跨度>
  • 你使用哪个 NodeJS 版本 @SarthakBhagwat ?
  • @TasosBu v12.18.3

标签: node.js reactjs npm create-react-app npx


【解决方案1】:

此错误通常发生在 PC 名称包含空格时

mycomputer name

你应该通过重新定义你的 npm 缓存根来解决这个问题。有一个简单的解决方法可以解决这个问题。 8.3 应使用 DOS 路径格式。在管理模式下打开命令提示符,然后 cd 到 C:\Users 并运行以下命令:

C:\Users>dir /x

并找到您想要的目录的短路径,即用户名让我们说它是 MYCOMP~1 (它并不总是 MYCOMP~1 ) 试试:

npm config set cache "C:\Users\MYCOMP~1\AppData\Roaming\npm-cache" --global

注意电脑名称中的空格字符,您应该使用从命令提示符获取的空格字符 现在使用:

npx create-react-app myapp

编码愉快!!!

【讨论】:

  • 像魅力一样工作......感谢您的指导
  • @SarthakBhagwat 真的帮助了我。谢谢!
  • 如果你的名字是Some Body Help,我应该输入什么?
  • 如果您严格按照这些步骤操作,它们应该仍然可以工作@Khant
【解决方案2】:

我参加聚会迟到了,但我的 PC 目录中的名称空间也遇到了同样的问题。我解决这个问题的方法是:

  1. 在 C 以外的其他位置创建空文件夹,例如在名为 folder/npm-cache 的 D 目录上
  2. 在终端中我运行: npm config set cache "D:\name-cache\AppData\Roaming\npm-cache" --global
  3. 如果您仍希望将其放在用户名中有空格的当前路径中

像“C:\Users\Firstname Lastname\AppData\Roaming\npm-cache” 你可以用“~1”替换空格后的字符串

npm config set cache "C:\Users\Firstname~1\AppData\Roaming\npm-cache" --global

此答案来自https://github.com/zkat/npx/issues/146

【讨论】:

    猜你喜欢
    • 2020-04-11
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 2011-03-19
    • 1970-01-01
    相关资源
    最近更新 更多