[Solved] NPM installation error: error: eacces: permission denied

Error:

sudo npm i webpack -g
/Users/xesfe/.npm-global/bin/webpack -> /Users/xesfe/.npm-global/lib/node_modules/webpack/bin/webpack.js
# System-wide .profile for sh(1)

> [email protected] install /Users/xesfe/.npm-global/lib/node_modules/webpack/node_modules/fsevents
> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/xesfe/.npm-global/lib/node_modules/webpack/node_modules/fsevents/build'
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/Users/xesfe/.nvm/versions/node/v10.16.2/bin/node" "/Users/xesfe/.nvm/versions/node/v10.16.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/xesfe/.npm-global/lib/node_modules/webpack/node_modules/fsevents
gyp ERR! node -v v10.16.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/webpack/node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ [email protected]
updated 1 package in 22.243s

Option 1:

 npm install --unsafe-perm=true --allow-root -g nodeppt

Nodeppt is always reported as an error during installation. The problem can be solved by checking the data and adding — unsafe perm = true — allow root. Issue on git: https://github.com/npm/npm/issues/17268 , this scheme doesn’t seem so elegant, so look for the second scheme

Option 2

1. Establish global folder configuration

mkdir ~/npm-global
 
npm config set prefix '~/npm-global'

PS: don’t create a configuration file starting with dot (.) under Mac, otherwise it still can’t be solved

2. Modify environment variables

vi /etc/profile 

If the file is read-only, change the read-write permission of the file

sudo chmod 777 /etc/profile

Append in/etc/profile

# npm配置
export PATH=~/npm-global/bin:$PATH

3. Activate environment variable configuration

source /etc/profile

4. Press again

i webpack -g
/Users/xesfe/npm-config/bin/webpack -> /Users/xesfe/npm-config/lib/node_modules/webpack/bin/webpack.js

> [email protected] install /Users/xesfe/npm-config/lib/node_modules/webpack/node_modules/fsevents
> node-gyp rebuild

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node
+ [email protected]

 

5. If you perform webpack discovery

zsh: command not found: webpack

Then add it to the environment variable

Do the following:

vi .bash_profile

In. Bash_Profile add

export NPM_CONFIG=~/npm-config
export PATH=$PATH:$NPM_CONFIG/bin

Execute the following command for the environment variable to take effect

source .bash_profile

 

Similar Posts: