2
votes

I'm trying to generate a new Angular project:

npm install -g @angular/cli

and there popped up an ERROR which I don't know how to solve:

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules/@angular/cli/node_modules/@schematics/update/node_modules/npm-package-arg/node_modules/semver
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli/node_modules/@schematics/update/node_modules/npm-package-arg/node_modules/semver'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli/node_modules/@schematics/update/node_modules/npm-package-arg/node_modules/semver']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/@angular/cli/node_modules/@schematics/update/node_modules/npm-package-arg/node_modules/semver\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/usr/local/lib/node_modules/@angular/cli/node_modules/@schematics/update/node_modules/npm-package-arg/node_modules/semver' }
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/simonanikolova/.npm/_logs/2020-07-04T16_47_21_985Z-debug.log

Some other specific things which may be relevant to the problem:

  • I have two logins on my Mac OS: admin user and personal user

  • macOS Catalina version: 10.15.5

  • npm version: 6.14.5

  • TypeScript version: 3.5.3

  • Angular version:

    Angular CLI: 9.0.0 Node: 10.16.1 OS: darwin x64

    Angular: undefined ... Ivy Workspace:

    Package Version @angular-devkit/architect 0.900.0 (cli-only) @angular-devkit/core 9.0.0 (cli-only) @angular-devkit/schematics 9.0.0 (cli-only) @schematics/angular 9.0.0 (cli-only) @schematics/update 0.900.0 (cli-only) webpack 4.43.0

ALSO: During my research how to solve the problem I have tried to change my file permission: I switched to my admin user and typed in the terminal:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

I will be very happy if somebody could help me! Thank you!

1

1 Answers

6
votes

If you did using a manual installation, once you install a package using sudo, you must keep using it to install them all.

A work around to your situation may be changing your NPM's default folder

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

  • Back up your computer
  • On the command line, in your home directory, create a directory for global installations: mkdir ~/.npm-global
  • Configure npm to use the new directory path: npm config set prefix '~/.npm-global'
  • In your preferred text editor, open or create a ~/.profile file and add this line:export PATH=~/.npm-global/bin:$PATH
  • On the command line, update your system variables: source ~/.profile
  • To test your new configuration, install a package globally without using sudo: npm install -g jshint
  • Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile):NPM_CONFIG_PREFIX=~/.npm-global

Another approuch may be reinstall your NPM using a node manager package (nvm, n)