"it does not contain a package.json file." npm install问题解决

困扰了2个小时终于搞定。

目的是要安装bignumber.js包

第一次出现问题:

npm WARN [email protected] No repository field.

+ [email protected]
added 1 package from 1 contributor, updated 1 package and audited 7 packages in 10.393s
found 0 vulnerabilities

说明问题主要是使用npm执行安装时,调用repository(库)失败。

也就是说repository里边可能没有bignumber的文件。

再次执行:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/bignumber.js" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/neo/.npm/_logs/2018-10-05T09_45_26_493Z-debug.log

这次报的错其实就已经很明显了。在package.json指定的库中没有包含这个文件。

于是,现在的任务主要就是package.json中添加包含这个文件的库。

直接输入npm命令,会显示npm的简介信息,里面包含npm安装的路径

neo@localhost:~/node_modules/neo$ npm

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    completion, config, create, ddp, dedupe, deprecate,
    dist-tag, docs, doctor, edit, explore, get, help,
    help-search, hook, i, init, install, install-test, it, link,
    list, ln, login, logout, ls, outdated, owner, pack, ping,
    prefix, profile, prune, publish, rb, rebuild, repo, restart,
    root, run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /Users/neo/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] /usr/local/lib/node_modules/npm

最后一行就是路径:cd到那个路径下,再cd到npm

$ cd /usr/local/lib/node_modules
$ cd npm/

里面包含一个package.json,这个文件就是我们要修改的文件。

neo@localhost:/usr/local/lib/node_modules/npm$ ls
AUTHORS         LICENSE         appveyor.yml    configure       lib             node_modules    scripts
CHANGELOG.md    Makefile        bin             doc             make.bat        npmrc
CONTRIBUTING.md README.md       changelogs      html            man             package.json

然后我们直接启动vi

$ vi package.json

在vi下,输入’/'然后再输入repository,再敲回车,查找到repository的位置

2805   "repository": {                                                                                                                    
2806     "type": "git",
2807     "url": "git+https://github.com/npm/cli.git"
2808   },

我的是2805行…前面是行号,可以忽略。

后面的这个url是关键。直接改成
https://github.com/MikeMcl/bignumber.js

保存退出,然后再执行

$ npm install --save bignumber.js
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/npm/node_modules
npm ERR! path /usr/local/lib/node_modules/npm/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/npm/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules/npm/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/neo/.npm/_logs/2018-10-05T10_51_39_317Z-debug.log

这个是权限拒绝。所以我们重新执行一下,请求一下权限sudo

$ sudo npm install --save bignumber.js
Password:
npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
added 1 package from 1 contributor and audited 5019 packages in 5.752s
found 0 vulnerabilities

回车,输入密码,搞定。

我们启动一下node,试试。

$ node
> require('bignumber.js')
{ [Function: BigNumber]
  clone: [Function: clone],
  ROUND_UP: 0,
  ROUND_DOWN: 1,
  ROUND_CEIL: 2,
  ROUND_FLOOR: 3,
  ROUND_HALF_UP: 4,
  ROUND_HALF_DOWN: 5,
  ROUND_HALF_EVEN: 6,
  ROUND_HALF_CEIL: 7,
  ROUND_HALF_FLOOR: 8,
  EUCLID: 9,
  set: [Function],
  config: [Function],
  isBigNumber: [Function],
  max: [Function],
  maximum: [Function],
  min: [Function],
  minimum: [Function],
  random: [Function],
  BigNumber: [Circular],
  default: [Circular] }

Have done~

你可能感兴趣的:(一些问题)