LoginSignup
1
0

More than 1 year has passed since last update.

Windows 上で npm が primordials is not defined で起動しない場合の破壊的解決法

Posted at

Windows上でWebアプリを開発する際に node.js を使いたいのに、
その環境構築の段階で、なぜか npm のバージョン確認すらできなくなり困ったので、
後々のためにメモを残します。

症状

C:\Users\****\>npm -v
evalmachine.<anonymous>:47
} = primordials;
    ^

ReferenceError: primordials is not defined
    at evalmachine.<anonymous>:47:5
    at Object.<anonymous> (C:\Users\****\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\fs.js:11:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\****\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\graceful-fs.js:3:27)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)

解決法

  1. node.js をアンインストールします。
    winget uninstall OpenJS.NodeJS
  2. Roaming配下のnpmフォルダを削除します。
    rmdir /s /q C:\Users\****\AppData\Roaming\npm
  3. node.js を再インストールします。
    winget install OpenJS.NodeJS.LTS

アンインストールと再インストールは winget を使ってもいいですし、コントロールパネルからアンインストール後、公式サイトから別途ダウンロードし他インストールパッケージを使ってインストールしてもいいです。個人的には winget を使うほうが断然楽なのでおすすめです。

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