Gyp err stack error eacces permission denied mkdir

Describe the bug amplify-cli fails to install using npm install -g @aws-amplify/cli gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/1...

Describe the bug
amplify-cli fails to install using npm install -g @aws-amplify/cli

gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/10.15.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/kerberos/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/kerberos/.node-gyp'
gyp ERR! System Linux 4.15.0-54-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/kerberos
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/10.15.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/fs-ext/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/fs-ext/.node-gyp'
gyp ERR! System Linux 4.15.0-54-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/fs-ext
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0

To Reproduce
docker run -it node:10-alpine sh -c «apk add python && npm install -g @aws-amplify/cli»

environment details
node 10 & 12. In used node’s docker image in the steps to reproduce. I came across this issue running ubuntu 16 and was able to replicate exactly in docker.

Additional context
Older versions still work. I was able to successfully install 1.7.1:

docker run -it node:12-alpine sh -c "apk add python && npm install -g @aws-amplify/cli@1.7.1"

При установке пакета Nodejs Browsertime я получил следующую ошибку.

npm install browsertime -g
/usr/bin/browsertime -> /usr/lib/node_modules/browsertime/bin/browsertime.js

> @sitespeed.io/chromedriver@77.0.3865-40 install /usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/chromedriver
> node install.js

(node:26690) UnhandledPromiseRejectionWarning: Error: Destination Folder must exist
    at DownloaderHelper.__validate (/usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/chromedriver/node_modules/node-downloader-helper/dist/index.js:390:23)
    at new DownloaderHelper (/usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/chromedriver/node_modules/node-downloader-helper/dist/index.js:61:20)
    at download (/usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/chromedriver/install.js:68:18)
(node:26690) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:26690) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

> @sitespeed.io/geckodriver@0.26.0 install /usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/geckodriver
> node install.js

(node:26701) UnhandledPromiseRejectionWarning: Error: Destination Folder must exist
    at DownloaderHelper.__validate (/usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/geckodriver/node_modules/node-downloader-helper/dist/index.js:387:23)
    at new DownloaderHelper (/usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/geckodriver/node_modules/node-downloader-helper/dist/index.js:61:20)
    at download (/usr/lib/node_modules/browsertime/node_modules/@sitespeed.io/geckodriver/install.js:73:18)
(node:26701) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:26701) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

> sharp@0.23.0 install /usr/lib/node_modules/browsertime/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

ERR! sharp EACCES: permission denied, mkdir '/root/.npm/_libvips'
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 WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/11.15.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/browsertime/node_modules/sharp/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/browsertime/node_modules/sharp/.node-gyp'
gyp ERR! System Linux 3.10.0-957.27.2.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/lib/node_modules/browsertime/node_modules/sharp
gyp ERR! node -v v11.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.23.0 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 sharp@0.23.0 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:

Я попробовал несколько вещей, но ничего не получалось.

После небольшого поиска я нашел документацию по npmjs и попробовал --unsafe-perm

npm install --unsafe-perm

Я надеюсь, что это вам тоже поможет.

There’s a bit of a headache going around with respect to global npm permissions. For those of us working on Unix-based systems, it’s not uncommon to come across error messages complaining about your user permissions whenever installing new npm packages, especially when installing them globally.

If errors like the one below  look familiar, you’re not alone:

npm WARN checkPermissions Missing write access to /Users/toddbirchard/.npm-packages/lib/node_modules
npm ERR! path /Users/toddbirchard/.npm-packages/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/toddbirchard/.npm-packages/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/Users/toddbirchard/.npm-packages/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access '/Users/toddbirchard/.npm-packages/lib/node_modules'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/Users/toddbirchard/.npm-packages/lib/node_modules' }
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 (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/toddbirchard/.npm/_logs/2019-05-05T20_36_45_642Z-debug.log
NPM permission errors

This is a textbook case of being trigger-happy with the sudo command. If you’re installing npm as a user other than root, it’s a bad idea to install Node + npm with the sudo command. If a non-root user installs dependencies by escalating privileges via sudo, the installation will appear to succeed. However, we’ve just created a scenario where the user in question does not have permission to modify global npm the user just installed (nor modify/install packages). When we installed Node/NPM with sudo, we handed exclusive ownership to the root user. That would mean we’d have to specify sudo before every global package install, which is annoying but more importantly unrealistic.

It gets worse. Npm packages that require post-install scripts to be run simply become impossible to install. Sometimes you might be able to get away with the following, but only if the scripts aren’t necessary:

$ npm i -g [package-name] --ignore-scripts
Install NPM package without running scripts post-execution

When the scripts are necessary, like in the case of node-sass, we’re shit outta luck. Using the --ignore-scripts flag just results in a broken install. Attempting to install using sudo looks like this:

$ sudo npm i -g node-sass

[sudo] password for todd:
/home/todd/.npm-global/bin/node-sass -> /home/todd/.npm-global/lib/node_modules/node-sass/bin/node-sass
Install node-sass globally

Uh oh….

Unable to save binary /home/todd/.npm-global/lib/node_modules/node-sass/vendor/linux-x64-64 : { Error: EACCES: permission denied, mkdir '/home/todd/.npm-global/lib/node_modules/node-sass/vendor'
    at Object.mkdirSync (fs.js:753:3)
    at sync (/home/todd/.npm-global/lib/node_modules/node-sass/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/home/todd/.npm-global/lib/node_modules/node-sass/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/home/todd/.npm-global/lib/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/home/todd/.npm-global/lib/node_modules/node-sass/scripts/install.js:157:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/home/todd/.npm-global/lib/node_modules/node-sass/vendor' }

> node-sass@4.12.0 postinstall /home/todd/.npm-global/lib/node_modules/node-sass
> node scripts/build.js

Building: /usr/bin/node /home/todd/.npm-global/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/bin/node',
gyp verb cli   '/home/todd/.npm-global/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.15.2 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.15
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 10.15.2
gyp verb command install [ '10.15.2' ]
gyp verb install input version string "10.15.2"
gyp verb install installing version: 10.15.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 10.15.2
gyp verb build dir attempting to create "build" dir: /home/todd/.npm-global/lib/node_modules/node-sass/build
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/todd/.npm-global/lib/node_modules/node-sass/build'
gyp ERR! System Linux 4.15.0-43-generic
gyp ERR! command "/usr/bin/node" "/home/todd/.npm-global/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /home/todd/.npm-global/lib/node_modules/node-sass
gyp ERR! node -v v10.15.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.12.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.12.0 postinstall 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/todd/.npm/_logs/2019-05-05T20_52_06_518Z-debug.log
NPM package installation error

Why does this happen? Because by default, the post-install scripts attempt to run as the current user. Since the current user doesn’t have permissions to mess with packages installed globally, the installation ultimately fails. To fix this, we need to reinstall Node the correct way.

Reinstalling Node

I’m working under the assumption that we’re using Ubuntu or a Debian-based Linux distro. The first thing we need to do is remove Node:

$ apt remove node
$ apt remove nodejs
Uninstall Node

Verify that Node is gone:

$ which node
Check Node version

If a folder path is returned by the above, nuke it. That should leave us ready for a fresh install.

Since we’re on a Debian system, we need to install Node via Nodesource. I’d recommend running this in the /tmp folder, or wherever you like to dump things saved from the internet:

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
$ apt-get install -y nodejs
Install Node from source

Now would be a good time to get the latest npm as well:

$ npm i -g npm@latest
Update NPM

When the installation is complete, check to see if everything worked:

$ node -v
> v16.13.0
Check Node version
$ npm -v
>> 8.12.1
Check NPM version

Create a New Global NPM Directory

With Node reinstalled, we can move on to creating and configuring a new directory to hold our global npm modules. You can name this what you want, but it’s generally recommended to name this npm-global or something of the sort. Don’t use sudo!

$ mkdir ~/.npm-global
Create a new home for global NPM modules

Now we can configure npm to recognize this folder:

$ npm config set prefix '~/.npm-global'
Configure NPM

Next, we need to add this to our PATH. This should go in ~/.bashrc (or ~/.bash_profile, depending on which you use):

$ echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc
Recognize new NPM path on startup

You Did Good

That should do it! From now on, remember to stray away from using sudo when installing Node, npm, or even modifying npm packages. The npm documentation explicitly recommends against this, but it’s all good. We all make mistakes.

Todd Birchard's' avatar

Engineer with an ongoing identity crisis. Breaks everything before learning best practices. Completely normal and emotionally stable.

Support us

We started sharing these tutorials to help and inspire new scientists and engineers around the world. If Hackers and Slackers has been helpful to you, feel free to buy us a coffee to keep us going :).

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Gyp err configure error gyp err stack error gyp failed with exit code 1
  • Gyp err build error gyp err stack error make failed with exit code 2
  • Gx gaming клавиатура как изменить цвет подсветки
  • Gw2 connection error s detected retrying
  • Gw2 a serious error

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии