如何使用NPM安装React?

huangapple go评论64阅读模式
英文:

How can I install React using NPM?

问题

无法使用npm安装React,出现了一些问题,我无法弄清楚问题出在哪。有谁知道如何解决这个问题吗?我卸载了npm并尝试重新安装,但没有帮助,还尝试了其他方法,但也没有帮助。

正在安装react、react-dom和react-scripts与cra-template...

npm ERR!代码ENOENT
npm ERR!系统调用打开
npm ERR!路径 D:\darslar\imtihon-app\node_modules\tailwindcss\oxide-node-api-shim/package.json
npm ERR!错误编号 -4058
npm ERR!enoent ENOENT:找不到文件或目录,打开'D:\darslar\imtihon-app\node_modules\tailwindcss\oxide-node-api-shim\package.json'
npm ERR!enoent 这与npm无法找到文件有关。
npm ERR!enoent 

npm ERR!此运行的完整日志可在以下位置找到:
npm ERR!C:\Users\User\AppData\Local\npm-cache\_logs23-02-08T15_57_28_764Z-debug-0.log

中止安装。
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template 已失败。

删除生成的文件... package.json
node:fs:1226
  return handleErrorFromBinding(ctx);
         ^

错误:EBUSY:资源繁忙或锁定,删除目录'\\?\D:\darslar\imtihon-app'
    at rmdirSync (node:fs:1226:10)
    at _rmdirSync (node:internal/fs/rimraf:235:5)
    at rimrafSync (node:internal/fs/rimraf:193:7)
    at Object.rmSync (node:fs:1275:10)
    at Object.removeSync (C:\Users\User\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\fs-extra\lib\remove\index.js:15:28)
    at C:\Users\User\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',
}

Node.js v18.12.0
英文:

I can't install react using npm for some reason, I can't figure out what the problem is. Does anyone know a solution to this problem? I uninstalled npm and tried again but it didn't help and tried other things. but it doesn't help me.

stalling react, react-dom, and react-scripts with cra-template...

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\darslar\imtihon-app\node_modules\tailwindcss\oxide-node-api-shim/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'D:\darslar\imtihon-app\node_modules\tailwindcss\oxide-node-api-shim\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Local\npm-cache\_logs23-02-08T15_57_28_764Z-debug-0.log

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
node:fs:1226
  return handleErrorFromBinding(ctx);
         ^

Error: EBUSY: resource busy or locked, rmdir '\\?\D:\darslar\imtihon-app'
    at rmdirSync (node:fs:1226:10)
    at _rmdirSync (node:internal/fs/rimraf:235:5)
    at rimrafSync (node:internal/fs/rimraf:193:7)
    at Object.rmSync (node:fs:1275:10)
    at Object.removeSync (C:\Users\User\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\fs-extra\lib\remove\index.js:15:28)
    at C:\Users\User\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',
}

Node.js v18.12.0



</details>


# 答案1
**得分**: 1

尝试以下步骤:

- 删除 `package-lock.json` 文件,然后再次运行 NPM。

- 确保没有其他 Node.js 进程在运行(检查任务管理器)。

- 如果您正在使用 Visual Studio Code,请关闭它,然后尝试再次运行 `npm install`。

您还可以查看以下问题页面:https://github.com/npm/npm/issues/17444

<details>
<summary>英文:</summary>

Try these steps:

 - Delete `package-lock.json` and run NPM again.

 - Ensure no other processes of node.js are running (check task manager)
 
 - If you are using visual studio code, close it and try running npm install again.

You can also check the following issue page: https://github.com/npm/npm/issues/17444

</details>



# 答案2
**得分**: 0

https://github.com/tailwindlabs/tailwindcss/issues/10534#issuecomment-1422896616

基本上,您需要更新 npm 到最新版本

```shell
npm install -g npm@latest

删除 package-lock.json 和 node_modules,然后运行

npm i

这是 cra 依赖的一个问题。整个世界都无法在一个小时内安装 react。

英文:

https://github.com/tailwindlabs/tailwindcss/issues/10534#issuecomment-1422896616

Basically you need update npm to latest version

npm install -g npm@latest

Delete package-lock.json and node_modules and launch

npm i

It was a problem with dependency of cra. Whole world couldn`t install react for one hour.

huangapple
  • 本文由 发表于 2023年2月9日 01:12:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定