无法使用npm install安装react-dom、react和next

问题描述 投票:0回答:1

我在项目中安装react-dom、react 和next 时遇到问题。我的项目中只有两个文件:index.js 和 package.json(我刚刚创建的文件是空的)。但当我跑步时

npm install react@latest react-dom@latest next@latest

在终端中它返回一个错误:

npm ERR! code EJSONPARSE
npm ERR! path C:\WEBSITES\Projets de la premiere cliente\platformes vente places d'installation/package.json
npm ERR! JSON.parse Unexpected end of JSON input while parsing empty string
npm ERR! JSON.parse Failed to parse JSON data.
npm ERR! JSON.parse Note: package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in: C:\Users\HP\AppData\Local\npm-cache\_logs\2024-01-26T03_19_04_697Z-debug-0.log

完整的日志在这里:

0 verbose cli C:\Program Files\nodejs\node.exe C:\Users\HP\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 4ms
4 timing config:load:defaults Completed in 8ms
5 timing config:load:file:C:\Users\HP\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 22ms
6 timing config:load:builtin Completed in 22ms
7 timing config:load:cli Completed in 4ms
8 timing config:load:env Completed in 2ms
9 timing config:load:file:C:\WEBSITES\Projets de la premiere cliente\platformes vente places d'installation\.npmrc Completed in 1ms
10 timing config:load:project Completed in 3ms
11 timing config:load:file:C:\Users\HP\.npmrc Completed in 0ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\HP\AppData\Roaming\npm\etc\npmrc Completed in 1ms
14 timing config:load:global Completed in 1ms
15 timing config:load:setEnvs Completed in 2ms
16 timing config:load Completed in 43ms
17 timing npm:load:configload Completed in 44ms
18 timing config:load:flatten Completed in 6ms
19 timing npm:load:mkdirpcache Completed in 0ms
20 timing npm:load:mkdirplogs Completed in 1ms
21 verbose title npm install react@latest react-dom@latest next@latest
22 verbose argv "install" "react@latest" "react-dom@latest" "next@latest"
23 timing npm:load:setTitle Completed in 5ms
24 timing npm:load:display Completed in 1ms
25 verbose logfile logs-max:10 dir:C:\Users\HP\AppData\Local\npm-cache\_logs\2024-01-26T03_19_04_697Z-
26 verbose logfile C:\Users\HP\AppData\Local\npm-cache\_logs\2024-01-26T03_19_04_697Z-debug-0.log
27 timing npm:load:logFile Completed in 1293ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 1417ms
31 timing arborist:ctor Completed in 2ms
32 silly logfile start cleaning logs, removing 2 files
33 timing idealTree Completed in 723ms
34 timing command:install Completed in 759ms
35 verbose stack JSONParseError: Unexpected end of JSON input while parsing empty string
35 verbose stack     at C:\Users\HP\AppData\Roaming\npm\node_modules\npm\node_modules\read-package-json-fast\lib\index.js:7:61
35 verbose stack     at async #initTree (C:\Users\HP\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:280:21)
35 verbose stack     at async Arborist.buildIdealTree (C:\Users\HP\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:193:7)
35 verbose stack     at async Promise.all (index 1)
35 verbose stack     at async Arborist.reify (C:\Users\HP\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:159:5)
35 verbose stack     at async Install.exec (C:\Users\HP\AppData\Roaming\npm\node_modules\npm\lib\commands\install.js:152:5)
35 verbose stack     at async module.exports (C:\Users\HP\AppData\Roaming\npm\node_modules\npm\lib\cli-entry.js:61:5)
36 verbose cwd C:\WEBSITES\Projets de la premiere cliente\platformes vente places d'installation
37 verbose Windows_NT 10.0.19045
38 verbose node v18.18.0
39 verbose npm  v10.2.1
40 error code EJSONPARSE
41 error path C:\WEBSITES\Projets de la premiere cliente\platformes vente places d'installation/package.json
42 error JSON.parse Unexpected end of JSON input while parsing empty string
43 error JSON.parse Failed to parse JSON data.
43 error JSON.parse Note: package.json must be actual JSON, not just JavaScript.
44 verbose exit 1
45 timing npm Completed in 4137ms
46 verbose unfinished npm timer reify 1706239147476
47 verbose unfinished npm timer reify:loadTrees 1706239147499
48 verbose unfinished npm timer idealTree:init 1706239147501
49 verbose code 1
50 error A complete log of this run can be found in: C:\Users\HP\AppData\Local\npm-cache\_logs\2024-01-26T03_19_04_697Z-debug-0.log

我尝试运行“npm clean cache”,但它不起作用。它返回给我一个错误:

npm ERR! As of npm@5, the npm cache self-heals from corruption issues
npm ERR!   data extracted from the cache is guaranteed to be valid.  If you
npm ERR!   want to make sure everything is consistent, use `npm cache verify`
npm ERR!   not likely to correct any problems you may be encountering!
npm ERR!
npm ERR!   On the other hand, if you're debugging an issue with the installer,
npm ERR!   or race conditions that depend on the timing of writing to an empty
npm ERR!   cache, you can use `npm install --cache /tmp/empty-cache` to use a
npm ERR!   temporary cache instead of nuking the actual one.
npm ERR!
npm ERR!   If you're sure you want to delete the entire cache, rerun this command
npm ERR!   with --force.
javascript node.js json cmd
1个回答
0
投票

您需要初始化package.json文件。首先,使用以下命令删除当前的 package.json 文件:

rm -rf package.json

之后,使用以下命令创建一个新的 package.json 文件:

npm init -y

它会起作用的!该错误是由于 package.json 文件为空(或创建不正确)而引起的。因此,当您尝试安装依赖项时,它无法将它们添加到文件中。

希望对您有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.