【问题标题】:why npm install don't work in ubuntu 18.04为什么 npm install 在 ubuntu 18.04 中不起作用
【发布时间】:2019-03-17 00:30:49
【问题描述】:

我正在尝试使用以下命令安装 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 没有创建,是我自己创建的,是空的。

【问题讨论】:

    标签: json npm ubuntu-18.04


    【解决方案1】:

    空的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
    

    【讨论】:

      猜你喜欢
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2016-06-25
      • 2020-10-13
      • 2019-06-07
      • 2022-01-12
      • 2019-12-11
      相关资源
      最近更新 更多