尝试运行命令 npx create react app 时创建 React App 出错:spawn UNKNOWN

vel*_*r11 6 javascript windows node.js reactjs create-react-app

当我尝试运行一个简单的程序时,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.
Run Code Online (Sandbox Code Playgroud)

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

我也在官方create-react-appgithub上提出了一个问题here

s.h*_*sam 0

我猜这个错误是由于不支持的全局安装而发生的create-react-app

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

npm uninstall -g create-react-app
Run Code Online (Sandbox Code Playgroud)

create-react-app然后按照这样的方式安装

npm install create-react-app
Run Code Online (Sandbox Code Playgroud)

然后创建你的反应应用程序

npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)