sudo npm install gives me a access denied

Viewed 9577

I am using ionic and I have fetched my project through git from machine1 to machine2.

My ionic infos gives me this :

[ERROR] Error with ./node_modules/@ionic/app-scripts/package.json file: FILE_NOT_FOUND

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

local packages:

@ionic/app-scripts : not installed
Ionic Framework    : ionic-angular 3.7.1

System:

Node : v8.9.1
npm  : 5.5.1
OS   : macOS High Sierra

Misc:

backend : pro

When I run sudo npm install I get the following :

npm WARN checkPermissions Missing write access to /Users/gerald/Documents/ionic/yesterdayweather/node_modules npm WARN checkPermissions Missing write access to /Users/gerald/Documents/ionic/yesterdayweather/node_modules/@ionic

And then

gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/gerald/Documents/ionic/yesterdayweather/node_modules/node-sass/build' gyp ERR! System Darwin 17.2.0 gyp ERR! command "/usr/local/Cellar/node/8.9.1/bin/node" "/Users/gerald/Documents/ionic/yesterdayweather/node_modules/node-gyp/bin/nod e-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /Users/gerald/Documents/ionic/yesterdayweather/node_modules/node-sass gyp ERR! node -v v8.9.1 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok Build failed with error code: 1 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.5.3 postinstall: node scripts/build.js npm ERR! Exit status 1

I have tried the following solution 1 and 3.

Basically I think I had node installed in a pkg way, so I removed it and intalled it with brew, so actually I should not have this issue.

But I tried anyway option 1 and it still does not work.

Any idea ?

Thanks !

2 Answers

It looks like a script is trying to write files, which npm by default denies when running as root. You can put --unsafe-perm behind the command to disable this safeguard.

You also should not run npm install with sudo because it is not necessary. Only when using the -g flag for installing modules globally should you use sudo.

2019 EDIT: It goes without saying that disabling safe guards like this can be very dangerous because you're giving a script a free pass to do whatever it wants. It's best to never use sudo and npm together, even when installing modules globally. If you're running into access issues with npm look into using a version manager or changing npm's default directory.

Related