1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

npm -v すら実行できなかった際の対応

Last updated at Posted at 2024-03-21

npm -v を実行すると以下のエラーが出た。
なんの操作をしてこのようになったのか記憶がない...

$ npm -v
ERROR: npm v10.2.5 is known not to run on Node.js v13.13.0.  This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

ERROR:
/Users/IsamuUmetsu/.nodebrew/node/v13.13.0/lib/node_modules/npm/lib/utils/exit-handler.js:19
  const hasLoadedNpm = npm?.config.loaded
                           ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:1039:16)
    at Module._compile (internal/modules/cjs/loader.js:1087:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:972:32)
    at Function.Module._load (internal/modules/cjs/loader.js:872:14)
    at Module.require (internal/modules/cjs/loader.js:1012:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at module.exports (/Users/IsamuUmetsu/.nodebrew/node/v13.13.0/lib/node_modules/npm/lib/cli-entry.js:15:23)
    at module.exports (/Users/IsamuUmetsu/.nodebrew/node/v13.13.0/lib/node_modules/npm/lib/es6/validate-engines.js:39:10)
    at module.exports (/Users/IsamuUmetsu/.nodebrew/node/v13.13.0/lib/node_modules/npm/lib/cli.js:4:31)

なぜか nvm がインストール済みで、 nvm lsv20.10.0 がインストール済みなので切り替えることに。

$ nvm ls
         v8.3.0
       v20.10.0
->       system

以下の流れで対応できたっぽい

$ nvm use v20.10.0
Your user’s .npmrc file (${HOME}/.npmrc)
has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.
Run `nvm use --delete-prefix v20.10.0` to unset it.

$ node -v #正常に切り替えられたことを確認
v20.10.0

$ npm -v #できるようになった
10.2.3

$ nvm use --delete-prefix v20.10.0
Now using node v20.10.0 (npm v10.2.3)
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?