【解決法】TypeScriptのインストールするとnpm ERR!,npm WARNと表示される

スポンサーリンク

【解決法】TypeScriptのインストールするとnpm ERR!,npm WARNと表示されることについて書きます。

■環境

・macOS High Sierra バージョン10.13.6

・Visual Studio Code バージョン1.46.1

■TypeScriptのインストール

npm install -g typescript

Node.jsをダウンロード後、Visual Studio Codeのターミナルを起動し、上記のコマンドを入力、Enterキーを押して、TypeScriptのインストールします。

USERnoMBookpuro:samples user$ npm install -g typescript
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2020-10-08T03_13_19_414Z-debug.log
USERnoMBookpuro:samples user$

インストールすると、上記のようなエラーが発生する場合があります。

■sudo(スーパーユーザ)の権限でインストールを行う

sudo npm install -g typescript

このような場合は、上記のコマンドを入力し、sudo(スーパーユーザー)の権限でインストールを行ってみます。

USERnoMBookpuro:samples user$ sudo npm install -g typescript
Password:
/usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/bin/tsserver -> /usr/local/lib/node_modules/typescript/bin/tsserver
+ typescript@4.0.3
added 1 package from 1 contributor in 0.749s

コマンドを入力し、Enterキーを押すと、「Password:」と表示されますので、macOS アカウントのパスワードを入力し、Enterキーを押すと、TypeScriptがインストールされます。

tsc -v

上記のコマンドでインストールが完了されたのか確認してみます。

「Version 4.0.3」と表示されましたので、TypeScriptのインストールが完了されたことが確認できました。

コメント

タイトルとURLをコピーしました