почему установка npm не работает в Ubuntu 18.04 - PullRequest
2 голосов
/ 16 марта 2019

Я пытаюсь установить hooper fpr на примере vue.js с помощью этой команды:

$ npm install hooper

и показать следующую ошибку

npm ERR! file /home/juanlh/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/juanlh/.npm/_logs/2019-03-16T14_39_47_947Z-debug.log

Журнал:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'install', 'hooper' ]
2 info using npm@6.9.0
3 info using node@v8.10.0
4 verbose config Skipping project config: /home/juanlh/.npmrc. (matches userconfig)
5 verbose npm-session e3d2c58aee19e2f6
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 timing stage:rollbackFailedOptional Completed in 6ms
9 timing stage:runTopLevelLifecycles Completed in 124ms
10 verbose stack Error: Failed to parse json
10 verbose stack Unexpected end of JSON input while parsing near ''
10 verbose stack     at parseError (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:452:11)
10 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:104:26)
10 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:51:5
10 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:16
10 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
11 verbose cwd /home/juanlh
12 verbose Linux 4.18.0-16-generic
13 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "install" "hooper"
14 verbose node v8.10.0
15 verbose npm  v6.9.0
16 error file /home/juanlh/package.json
17 error code EJSONPARSE
18 error JSON.parse Failed to parse json
18 error JSON.parse Unexpected end of JSON input while parsing near ''
19 error JSON.parse Failed to parse package.json data.
19 error JSON.parse package.json must be actual JSON, not just JavaScript.
20 verbose exit [ 1, true ]

Package.json не был создан, я создаю его сам и он пуст.

1 Ответ

3 голосов
/ 16 марта 2019

Пустой package.json недопустим json (и, следовательно, не является действительным package.json)

Например

$ echo -n > package.json

$ npm install left-pad
npm ERR! file /tmp/x/x/x/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/asottile/.npm/_logs/2019-03-16T16_28_09_404Z-debug.log

Минимальный package.json для выполнения установки {} (это действительно json: пустая карта)

$ echo '{}' > package.json
$ npm install left-pad
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN x No description
npm WARN x No repository field.
npm WARN x No license field.

+ left-pad@1.3.0
added 1 package from 1 contributor and audited 1 package in 0.677s
found 0 vulnerabilities

Вы также можете просто полностью удалить package.json:

$ rm -rf package.json node_modules
$ npm install left-pad
npm WARN saveError ENOENT: no such file or directory, open '/tmp/x/x/x/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/tmp/x/x/x/package.json'
npm WARN x No description
npm WARN x No repository field.
npm WARN x No README data
npm WARN x No license field.

+ left-pad@1.3.0
...