【问题标题】:Create React App Error when trying to run command npx create react app: spawn UNKNOWN尝试运行命令时创建 React App 错误 npx create react app: spawn UNKNOWN
【发布时间】:2021-06-07 23:57:18
【问题描述】:

当我尝试运行一个简单的npx create-react-app 时,我收到了这个错误:

D:\>npx create-react-app abc
npx: installed 67 in 4.255s

Creating a new React app in D:\abc.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...


Aborting installation.
Unexpected error. Please report it as a bug:
Error: spawn UNKNOWN
    at ChildProcess.spawn (internal/child_process.js:403:11)
    at Object.spawn (child_process.js:553:9)
    at spawn (C:\Users\Gilang\AppData\Roaming\npm-cache\_npx\17768\node_modules\create-react-app\node_modules\cross-spawn\index.js:12:24)
    at C:\Users\Gilang\AppData\Roaming\npm-cache\_npx\17768\node_modules\create-react-app\createReactApp.js:407:19
    at new Promise (<anonymous>)
    at install (C:\Users\Gilang\AppData\Roaming\npm-cache\_npx\17768\node_modules\create-react-app\createReactApp.js:359:10)
    at C:\Users\Gilang\AppData\Roaming\npm-cache\_npx\17768\node_modules\create-react-app\createReactApp.js:485:16
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  errno: -4094,
  code: 'UNKNOWN',
  syscall: 'spawn'
}

Deleting generated file... package.json
Deleting abc/ from D:\
Done.

我使用的是 Windows 10 版本 20H2 和节点 v14.15.4。

我在官方create-react-appgithubhere也发过issue了

【问题讨论】:

  • 尝试全局安装npm install -g create-react-app,然后使用create-react-app abc 看看是否有效
  • 感谢您的建议,但我仍然遇到同样的错误。 @TarunLalwani
  • 你的节点版本是多少?
  • 正如我的问题中提到的,我正在使用node v14.15.4.@TarunLalwani
  • 我无法使用node v14.15.4npx create-react-app abc 重现此问题。我建议你卸载 node.js 并重新安装并重试。

标签: node.js reactjs windows create-react-app


【解决方案1】:

昨天我遇到了同样的问题。 TBH 我也不知道是什么原因造成的,但在浏览了一些网站和 YouTube 教程后,我终于找到了解决这个问题的方法。

首先,您需要根据使用的系统了解在您的 PC 或笔记本电脑上运行的最佳节点版本。

其次,点击windowsWIN+r去运行管理,写%tempt%把里面的文件全部删除,不能删除的就跳过,然后再次在运行管理的搜索栏上写prefetch,并像以前一样删除里面的所有文件。

之后打开Node.js command prompt(您可以在搜索探索栏上找到它)但不要忘记已经安装了Node.js。单击箭头并选择以管理员身份运行,命令提示符界面将打开。

注意C:\Windows\System32&gt;已经默认写入了,所以你需要在windows的System32部分中创建文件夹。假设你制作了这个examplereactjs(确保使用非大写字母,因为我不知道为什么我使用大写字母时不会运行),之后,你可以像往常一样制作你的npx应该是这样的:

C:\Windows\system32>cd examplereactjs

回车,会是这样的:

C:\Windows\system32\examplereactjs>npx create-react-app examplereactjs

按 Enter,然后等待几分钟。您可以以npm start 开头,打开本地主机浏览器。

这个方法对我有用,实际上是我偶然发现的。如果这对你不起作用,我不知道还有什么可以。我还是这个领域的新手,我不知道如果你搞乱运行管理会导致什么,我只是来帮忙。无论如何,让我知道这种方法是否也适合您。

【讨论】:

    【解决方案2】:

    您可以尝试使用:

       npm cache clear --force
    

    然后重试。

    根据网站https://create-react-app.dev/docs/getting-started/,有提到:

    如果您之前通过 npm install -g >create->react-app 全局安装了 create-react-app,我们建议您使用 npm uninstall -g create->react-app 或 yarn global remove create 卸载包-react-app 以确保 npx 始终使用 >latest 版本。

    【讨论】:

      【解决方案3】:

      好像写权限有问题。

      尝试使用提升的权限从 cmd 运行 npx create-react-app myapp,即以管理员身份运行 cmd,然后尝试创建/搭建您的应用程序。

      【讨论】:

        【解决方案4】:

        我猜这个错误是因为不支持全局安装create-react-app

        这个问题有一个小问题,那就是不再支持create-react-app 的全局安装。所以首先,运行这个命令

        npm uninstall -g create-react-app
        

        然后这样安装create-react-app

        npm install create-react-app
        

        然后创建你的 react 应用

        npx create-react-app my-app
        

        【讨论】:

          猜你喜欢
          • 2022-06-14
          • 2020-08-11
          • 1970-01-01
          • 1970-01-01
          • 2023-02-14
          • 2021-04-28
          • 1970-01-01
          • 2022-01-07
          • 1970-01-01
          相关资源
          最近更新 更多