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を使えるようにする

Posted at

背景

vscodeで、qita-cliを使いたかったので、npmが必要だった。

手順

vscodeからインストールはできない。本家サイトにいく。

msiをインストールして、vscodeを再起動。

$node -v
v22.18.0

こんなかんじ

npm install @qiita/qiita-cli --save-dev
npm : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Program Files\nodejs\npm.ps1 を読み込むことができません。詳細については、「about_Execu
tion_Policies」(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ npm install @qiita/qiita-cli --save-dev
+ ~~~
    + CategoryInfo          : セキュリティ エラー: (: ) []、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

入れてみるとエラー。geminiに聞いてみる。

このエラーは、WindowsのPowerShellで発生するものです。

これは、npmが使うスクリプト(npm.ps1)を、 PowerShellのセキュリティ設定(実行ポリシー)が原因で実行できないことを示しています。

なぜこのエラーが出るのか?
WindowsのPowerShellには、悪意のあるスクリプトの実行を防ぐためのセキュリティ機能が備わっています。

npmコマンドは、内部でこのnpm.ps1というスクリプトファイルを利用しますが、デフォルトの設定では、このスクリプトの実行が許可されていないため、エラーとなってしまうのです。

管理者権限でpowershellを起動し以下を実行

Set-ExecutionPolicy RemoteSigned

ローカル作成のスクリプトは実行可能だが、インターネットからDLしたものは署名が必要、という設定。

以上で、vscodeでインストールができるようになる

npm install @qiita/qiita-cli --save-dev

added 121 packages, and audited 122 packages in 7s

39 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 10.9.3 -> 11.5.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.5.2
npm notice To update run: npm install -g npm@11.5.2
npm notice
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?