简体   繁体   中英

Error when Create React App in Windows with npx

I've got NODE (current version: 18.9.0) installed in my laptop and trying to create a react app but always fails.

npx create-react-app my-app-one

The error I'm getting

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

Then looking at warnings etc I've done below

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

Still when I'm trying to create a react app I'm getting following error. I ran command prompt Administrator mode, changed location to D drive, un-installed and re-installed Node few times restarting laptop as well. But no luck. If someone has experienced this and know a solution please guide me. Thanks!

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

I think your problem is the node version you should downgrade it to 17

"react": "^18.0.0",
"react-dom": "^18.0.0"
-----------------------
"react": "^17.0.0",
"react-dom": "^17.0.0"

or allow legacy-peer-deps

npm config set legacy-peer-deps true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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