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

Windowsで npm が実行できないときの対処法(ExecutionPolicy エラー)

0
Posted at

はじめに

Windowsでちょっと開発したくてセットアップした時にnpmインストールできない問題に引っかかったので、対処法をメモ。

発生したエラー

PS C:\Users\username\WORKSPACE\repository> npm -v
npm : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Program Files\nodejs\npm.ps1 を読み込むことができません。詳細につい

ては、「about_Execution_Policies(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。

発生場所 :1 文字:1

+ npm -v

+ ~~~

    + CategoryInfo          : セキュリティ エラー: (: ) []PSSecurityException

    + FullyQualifiedErrorId : UnauthorizedAccess

原因

Windows PowerShell では、スクリプトの実行ポリシー(ExecutionPolicy) によって.ps1 ファイルの実行が制限されている場合がある。

そのため、

  • npm は内部的に npm.ps1 を実行する
  • 実行ポリシーにより .ps1 の実行が制限されている

結果、エラーが発生します ⚠️

対処法

1. PowerShellを管理者権限で起動

スタートメニューから、"Windows Powershell"

”管理者として開く“

2. 実行ポリシーを変更

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

確認メッセージが表示されるのでY(はい)を入力する。
※ Scope CurrentUser: 現在のユーザのみに影響するので、比較的安全。

3. 確認

PS C:\Users\username\WORKSPACE\repository> npm -v 
11.6.2

👍🎉

まとめ

npm が実行できない場合、PowerShell の ExecutionPolicy を確認する。
参考になれば幸いです🍏

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