"it does not contain a package.json file."npm install問題解決

10760 ワード

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/

パッケージが含まれています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~