EACCES:sudoを使用すると権限が拒否されました。

EACCES:sudoを使用すると権限が拒否されました。

NPMを使用してノードパッケージをインストールしようとしていますが、権限エラーのみが表示されます。昨日問題なくパッケージをインストールできましたが、何らかの理由で動作が停止しました。

asgeir@1e19udt0shu6:~/nodejs/first_test_app$ sudo npm install sharp

> [email protected] install /home/asgeir/nodejs/first_test_app/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.4/libvips-8.7.4-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, open '/home/asgeir/nodejs/first_test_app/node_modules/sharp/9016-libvips-8.7.4-linux-x64.tar.gz'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/asgeir/nodejs/first_test_app/node_modules/sharp/build'
gyp ERR! System Linux 2.6.32-042stab133.2
gyp ERR! command "/usr/local/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/asgeir/nodejs/first_test_app/node_modules/sharp
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/asgeir/.npm/_logs/2019-07-17T06_16_33_097Z-debug.log

インターネットを検索した後、一部の魂の人々が同じエラーを受けていることがわかりました。明らかにNPMとNodeJSを再インストールして動作させましたが、私は成功しませんでした。このエラーを克服する方法についてのアイデアはありますか?

ベストアンサー1

別の極端なインターネット検索の最後に、次の解決策を見つけました。

NPMにSharpパッケージをインストールさせるには、このコマンドを使用します。

sudo npm install --unsafe-perm=true --allow-root

特定のモジュールをダウンロードする必要がある場合は、ダウンロードする必要がある依存関係を表示します。

sudo npm install dependency-name --unsafe-perm=true --allow-root

私はLinuxのエチケットについてはよくわかりませんが、このコマンドは犯罪のように感じます。しかし、動作します!

編集:うまくいかない場合はお試しください。SOでこの記事を見つけました。

おすすめ記事