LoginSignup
12
7

More than 3 years have passed since last update.

なぜか上がらないnpmのバージョン

Last updated at Posted at 2020-09-06

開発環境
npm : 3.5.2
Ubuntu :18.0.03

問題

npm insatll を実行しようとした際にエラーが表示しました。

npm ERR! Linux 5.4.0-45-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "update"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code EMISSINGARG

npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror     at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror     at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror     at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror     at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror     at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror     <http://github.com/npm/npm/issues>

意味としてはnpmのパッケージのバージョンが要求されているものと合ってないよ~」ということでネット上にはバージョンを最新に上げれば直るということで色々試したのですが。。。。

npm --version 
3.5.2

sudo npm install -g npm@latest
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.14.8
updated 1 package in 5.5s

sudo npm install -g npm@nex
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.14.8
updated 1 package in 5.5s

npm --version 
3.5.2

上記のコマンドで一見上がっているように見えるのですが、実際にもう一度npmのバージョンを見てみると上がってない!!
なんじゃこれ状態ですね~

解決方法

調べてみるとnpmのリポジトリがサポートしなくなっているみたいなので、手動で落としてきましょう~

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -       
sudo apt -y install nodejs make gcc g++

これでいけるかな~と思ったのですが、、

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/administrator/.npm/_cacache/content-v2/sha512/5b/ec
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/home/administrator/.npm"
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/administrator/.npm/_cacache/content-v2/sha512/bd/c5........

前のバージョンのキャッシュが残っていて、「なんや!! このファイルは?」となっているみたいなので、キャッシュを消しときましょう

sudo npm cache clean --force 

あとは普通にnpm installをたたけばいけますよ~

sudo npm install

まとめ

今回の問題は発生するのは主にUbuntu系の環境で作業されている方だと思います。
それ以外の方はおそらくlatestやnextを実行したときに上がっていると思うので、単純にUbuntu環境ではnpmリポジトリのサポートが3.5.2できれてしまっているのが原因ですかね~

参考資料

12
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
7