NPM permission error installing modules for material design - npm

So, I really want to get started using material design. I'm using their getting started guide (https://material.io/develop/web/docs/getting-started/). Everything worked until the part where I have to install the modules. There I got the error:
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/paul/Code/Material_Design_Test/Test4/node_modules/node-sass/build'
And then because of this the npm start command did not work either.
I've tried running it with sudo, same error. Tried to give me ownership of the folders, as sudo. Nothing worked.

you may run with sudo mode or else give the folder ownership with your user account and try to run it again
chown -R yourusername:yourusername directory

Related

Error "Cannot read property "matches" of undefined" when using "npm install"

I'm trying to install expo globally on my Windows 10 machine for a school assignement.
As the doc says, I've been trying the following command in my terminal :
$ npm install --global expo-cli
but it always gives me the same error :
npm ERR! Cannot read property 'matches' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2021-04-07T13_43_16_562Z-debug.log
I've tried running $ npm install -g expo-cli instead but the same thing happens.
I haven't tried reinstalling node or anything yet because I need my pc up and running for this week and I'm not too accustomed to all that, I'd like to keep that a last resort if possible.
Has anyone ever encountered this error before ?
Thanks to those who replied but I "accidentally" fixed it myself.
Through my searching I ended up actually uninstalling node with $ nvm uninstall v15.0.0 and I found myself obligated to download it again here.
Must've been a problem with the version I was using as suggested before.
Try removing the node_modules folder and package-lock.json file and run command npm install.

npm ERR! It is likely you do not have the permissions to access this file as the current user on Mac

I am trying to run the the command npm install -y but I keep getting the following error...
enter image description here
I've tried to run sudo npm install -y but that hasn't gotten me anywhere. Any ideas?
The error message says that may need to run as root/admin but I'm pretty sure that I'm running as the admin. Any help would be appreciated!
You should not be running npm under sudo. Instead you need to make sure that your directory and all sub-directories are writable by you.
To be safe, I would delete your current install, and restart in a directory where you know the current user has write permissions.
If you can't do that, then run the following command to make sure that your user has permission to write (be aware that this will not work if you don't have su access on your machine in the directory you are in:
sudo chown -R <youruser>:<youruser> *
sudo chmod -R u+w *
Be careful since this will change ownership and permissions on all files in the subtree (except for files beginning with .).

npm: Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/me/.npm/_cacache/content-v2/sha512/b3/da’

On my Mac, I just updated my working npm version from 5.6 to 6.9 thusly:
sudo npm i -g npm
Then I tried to install cordova like this:
sudo npm install -g cordova
And get
Unhandled rejection Error: EISDIR: illegal operation on a directory,
open '/Users/me/.npm/_cacache/content-v2/sha512/04/89'
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/me/.npm/_logs/2019-04-02T11_50_57_678Z-debug.log
I tried to downgrade thusly:
sudo npm install -g npm#6.4.1
but this fails with hundreds of lines like this:
npm WARN tar EISDIR: illegal operation on a directory, open '/tmp/npm-30934-a3ac319a/unpack-28da209e/bin/node-gyp-bin'
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/content-v2/sha512/99/72'
I also tried making sure the ownership was correct:
sudo chown -R $(whoami) ~/.npm
There are lots of posts of various EISDIR (error is a directory) problems for other directories (such as /usr/lib/modules), but no solutions seem to work.
Also, the npmrc file does not seem to exist. If I do:
npm config ls -l
globalconfig = "/usr/local/etc/npmrc"
userconfig = "/Users/me/.npmrc"
but neither file exists.
Note, I dont have homebrew, and didnt install it that way (I usually do manual installs).
I also tried this:
sudo npm cache clean -f
This did not help.
What else can I try? should I try deleting the ~/.npm dir?
Looking for a way to uninstall node, I found many old posts with long and sometimes conflicting lists of files to remove. Not sure if this will make it worse.
Any suggestions?
I think I have found a solution. I did the following:
installed node from the Mac pkg installer from https://nodejs.org/en/ This downgraded npm to 6.4.1 which is the version before EISDIR problems start apparently.
chmod -R 777 ~/.npm/_cacache // yes, this is not good
chown -R me ~/.npm/_cacache
After this, I could install cordova using "sudo npm install -g cordova" without errors.
I had the same problem when I upgraded to npm 6.9.0. You have to upgrade node to the last version:
brew reinstall node
At this time I have installed the latest available version for Mac OS Mojave (node: v11.14.0 and npm 6.9.0).
After node upgrade, I was able to install packages globally again.
Changing the ownership of files and then avoiding the use of sudo is a possible workaround for EISDIR with global installs using sudo. I suppose you have installed to default location folder:
sudo chown -R <user> ~/.npm
sudo chown -R <user> /usr/local/lib
sudo chown -R <user> /usr/local/bin
After this sequence, it worked to me.

NPM `EACCES` error, not fixed by changing the default directory

I was getting an EACCES error from NPM so I followed these directions to fix it by changing the default directory: https://docs.npmjs.com/getting-started/fixing-npm-permissions Using the test they gave at the end, I installed jshint globally without error.
However, when I try to build an Angular project
sudo ng new ProjectName --style=scss --routing
I get a lot of errors, the first one being
Unable to save binary /home/addem/Web/ExplainAngular/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/home/addem/Web/ExplainAngular/node_modules/node-sass/vendor'
I then followed these instructions: Error: EACCES: permission denied
Still doesn't fix the problem, so at this point I'm not sure what to do.
I discovered the cause. I had installed the Angular CLI before I followed the fixes above, and therefore the Angular CLI did not have all the ... "stuff" it needed. I guess maybe dependencies or packages. Anyway, after doing the above fixes and then running
npm install -g #angular/cli
I can now create the project without errors.

npm install error EACCES permission denied?

I have permission problem using npm.
When I write "npm install"
Error: EACCES: permission denied, mkdir '/ItsMe'
TypeError: Cannot read property 'get' of undefined
at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:211:17)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:83:20
at cb (/usr/local/lib/node_modules/npm/lib/npm.js:215:22)
at /usr/local/lib/node_modules/npm/lib/npm.js:253:24
at /usr/local/lib/node_modules/npm/lib/config/core.js:81:7
at Array.forEach (native)
at /usr/local/lib/node_modules/npm/lib/config/core.js:80:13
at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:178:20)
at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:235:20)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:211
if (npm.config.get('json')) {
^
TypeError: Cannot read property 'get' of undefined
at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:211:17)
at emitOne (events.js:96:13)
at process.emit (events.js:191:7)
at process._fatalException (bootstrap_node.js:304:26)
With a "ls -l" I have rwx rights.
I don't understand what "Cannot read property 'get' of undefined" means.
I searched on the web and tried several things but it' doesn't work.
Could you help me ?
Thank you
Your npm install try to do an mkdir in a file you don't have access to. Try to give him the right by doing
sudo npm install
or doing it as a super user (I dont recomand that) You also asked what npm install do without argument. Well if ou don't specify a folder it creates the folder node_module (that is why it does an mkdir). If you don't precise a module it will install all the module from package.json. It can take morte time and you will have a lots of package you won't need but with that you will be sure to have the one you want.
You can choose the package you want if you exactly know wich one. ie :
npm install sax#latest
the latest mean it gonna search for the last existing package
ANd you can also install a package you downloaded yourself. ie :
npm install ./package.tgz