0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dockerでnpx @angular/cli newしてエラーが出る時の対処法

Posted at

問題

npxを使うと@angular/cliをグローバルインストールせずにプロジェクトを作成できます。

npx @angular/cli new foo

しかしdockerで同じコマンドを実行するとエラーになります。

internal/modules/cjs/loader.js:1033
  throw err;
  ^

Error: Cannot find module '/root/.npm/_npx/800/lib/node_modules/@angular/cli/bin/postinstall/script.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)
    at Function.Module._load (internal/modules/cjs/loader.js:899:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @angular/cli@10.0.2 postinstall: `node ./bin/postinstall/script.js`
npm ERR! Exit status 1

回避策

どうもrootユーザーなのが問題なようです。
--unsafe-permを指定したいところですがnpxには--unsafe-permオプションが無さそうなので環境変数で渡します。

npm_config_unsafe_perm=true npx @angular/cli new foo

これで無事にプロジェクトを作成できました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?