我遇到了一个问题,在我的项目中安装REACTION-DOM、REACT和NEXT.我在项目中只有两个文件:index.jspackage.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

完成日志(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 npm@10.2.1
2 info using node@v18.18.0
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.

推荐答案

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

rm -rf package.json

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

npm init -y

看起来不错!导致该错误的原因是Package.json文件为空(或创建不正确).因此,当您try 安装依赖项时,它无法将它们添加到文件中.

我希望我能帮上忙!

Javascript相关问答推荐

用相器进行向内碰撞检测

如何通过onClick为一组按钮分配功能;

禁用从vue.js 2中的循环创建的表的最后td的按钮

如何使用侧边滚动按钮具体滚动每4个格?

网页自检测外部元素无法加载

Rehype将hashtag呈现为URL

google docs boldText直到按行执行应用脚本错误

自定义高图中的x轴标签序列

数字时钟在JavaScript中不动态更新

html + java script!需要帮助来了解为什么我得到(无效的用户名或密码)

使用ThreeJ渲染的形状具有抖动/模糊的边缘

编辑文本无响应.onClick(扩展脚本)

如何在JAVASCRIPT中临时删除eventListener?

以编程方式聚焦的链接将被聚焦,但样式不适用

SPAN不会在点击时关闭模式,尽管它们可以发送日志(log)等

Phaserjs-创建带有层纹理的精灵层以自定义外观

P5.js中的分形树

ngOnChanges仅在第二次调用时才触发

将Singleton实例设置为未定义后的Angular 变量引用持久性行为

bootstrap S JS赢得了REACT中的函数/加载