[英]Error when Create React App in Windows with 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
我認為您的問題是您應該將其降級到 17 的節點版本
"react": "^18.0.0",
"react-dom": "^18.0.0"
-----------------------
"react": "^17.0.0",
"react-dom": "^17.0.0"
或允許 legacy-peer-deps
npm config set legacy-peer-deps true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.