繁体   English   中英

使用 npx 在 Windows 中创建新的 React 应用程序时出错

[英]Error when create a new React App in Windows using npx

我已经在我的计算机中安装了 NODE(当前版本:18.9.0)并尝试创建一个反应应用程序,但总是失败。

npx create-react-app my-app-one

我得到的错误:

C:\Users\MyName\Documents\React>npx create-react-app my-app-one
Need to install the following packages:
  create-react-app@5.0.1
Ok to proceed? (y) y
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

Creating a new React app in C:\Users\MyName\Documents\React\my-app-one.

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 (node:internal/child_process:413:11)
    at Object.spawn (node:child_process:743:9)
    at spawn (C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\cross-spawn\index.js:12:24)
    at C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:383:19
    at new Promise (<anonymous>)
    at install (C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:334:10)
    at C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:461:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -4094,
  code: 'UNKNOWN',
  syscall: 'spawn'
}

Deleting generated file... package.json
Deleting my-app-one/ from C:\Users\MyName\Documents\React
Done.
npm notice
npm notice New patch version of npm available! 8.19.1 -> 8.19.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2
npm notice Run npm install -g npm@8.19.2 to update!
npm notice

然后查看我在下面完成的警告等

npm i tar                    <- This is to fix warning deprecated tar@2.2.2
npm install -g npm@8.19.2    <- To update npm minor version

仍然当我尝试创建一个反应应用程序时,我遇到了以下错误。

  • 我运行命令提示符管理员模式。
  • 将位置更改为D盘并尝试。
  • 卸载并重新安装Node几次并重新启动机器。

如果有人经历过这种情况并知道解决方案想听。 谢谢!

C:\Users\MyName\Documents\React>npx create-react-app app-xyz

Creating a new React app in C:\Users\MyName\Documents\React\app-xyz.

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


Aborting installation.
  npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json
Deleting app-xyz/ from C:\Users\MyName\Documents\React
node:fs:1225
  return handleErrorFromBinding(ctx);
         ^

Error: EBUSY: resource busy or locked, rmdir '\\?\C:\Users\MyName\Documents\React\app-xyz'
    at rmdirSync (node:fs:1225:10)
    at _rmdirSync (node:internal/fs/rimraf:235:5)
    at rimrafSync (node:internal/fs/rimraf:193:7)
    at Object.rmSync (node:fs:1274:10)
    at Object.removeSync (C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\fs-extra\lib\remove\index.js:15:28)
    at C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:539:14
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -4082,
  syscall: 'rmdir',
  code: 'EBUSY',
  path: '\\\\?\\C:\\Users\\MyName\\Documents\\React\\app-xyz'
}

Node.js v18.9.0

编辑

还安装了 YARN 并尝试了以下操作。

npm install -g yarn
yarn global add create-react-app
yarn create react-app my-app

还是一样的错误:

C:\Users\MyName\Desktop\Apps>yarn create react-app my-app
yarn create v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Installed "create-react-app@5.0.1" with binaries:
      - create-react-app

Creating a new React app in C:\Users\MyName\Desktop\Apps\my-app.

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


Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template --cwd C:\Users\MyName\Desktop\Apps\my-app has failed.

Deleting generated file... package.json
Deleting my-app/ from C:\Users\MyName\Desktop\Apps
Done.
error Command failed.
Exit code: 1
Command: C:\Users\MyName\AppData\Local\Yarn\bin\create-react-app
Arguments: my-app
Directory: C:\Users\MyName\Desktop\Apps
Output:

info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.

我建议您使用命令npm create-react-app -g将 create-react-app 安装为全局,之后您可以运行`npx create-react-app [文件名],如果失败只是

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM