microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.55k stars 823 forks source link

npm package fails to install "npm ERR! Error: EACCES: permission denied" #14

Closed pallatee closed 8 years ago

pallatee commented 8 years ago

While trying to install a packge with npm (for example lodash) it fails with error message:

npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "lodash"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! path /root/test/node_modules/.staging/lodash-9a2aabe2
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename

npm ERR! Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash'
npm ERR!     at destStatted (/usr/lib/node_modules/npm/lib/install/action/finalize.js:25:7)
npm ERR!     at FSReqWrap.oncomplete (fs.js:82:15)
npm ERR!
npm ERR! Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash'
npm ERR!     at Error (native)
npm ERR!  [Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash']
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/test/npm-debug.log

I have tried to install it both with and without starting bash in administrator mode.

borovaka commented 8 years ago

There is another wired thing about npm. When I try to install gulp globally I get:

Error: could not get uid/gid
net.js:135
    this._handle.open(options.fd);
                 ^

Error: EINVAL: invalid argument, uv_pipe_open
    at Error (native)
    at new Socket (net.js:135:18)
    at createWritableStdioStream (internal/process/stdio.js:142:16)
    at process.stdout (internal/process/stdio.js:10:14)
    at console.js:99:37
    at NativeModule.compile (node.js:395:5)
    at Function.NativeModule.require (node.js:340:18)
    at node.js:223:27
    at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/uid-number/get-uid-gid.js:16:1)
    at Module._compile (module.js:413:34)

    at /usr/lib/node_modules/npm/node_modules/uid-number/uid-number.js:37:16
    at ChildProcess.exithandler (child_process.js:209:5)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:90:13)
    at Socket.emit (events.js:182:7)
    at Pipe._onclose (net.js:475:12)
jamesscholeyweb commented 8 years ago

Same here. In fact if I try to update npm update -g npm@latest it attempts to copy lodash to the staging directory then throws the errror. Following this subsequent attempts to use npm are broken because it can no longer find lodash.

IMPORTANT

This really should be of utmost importance to the team. I for one was very excited and love how everything else works, but as you are adding this feature to windows with the intention of bringing web developers back to windows this needs fixing ASAP. This alone will stop me switching back to windows for web development and I'm sure it will be the same for many. It defeats the purpose of switching for me. Please please please fix.

jgchristopher commented 8 years ago

@borovaka you can fix that error by allowing unsafe perms

npm config set unsafe-perm=true

jamesscholeyweb commented 8 years ago

Already tried. It bypasses the error but it still doesn't work. You will get a permissions access error still or at least I did.

On Friday, April 8, 2016, John Christopher notifications@github.com wrote:

@borovaka https://github.com/borovaka you can fix that error by allowing unsafe perms

npm config set unsafe-perm=true

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/Microsoft/BashOnWindows/issues/14#issuecomment-207504657

jgchristopher commented 8 years ago

@jamesscholeyweb right, I was able to get to your error after setting those perms. Otherwise I wasn't able to do anything.

jgchristopher commented 8 years ago

This seems to be the underlying issue.

root@localhost:/usr/lib/node_modules/.staging# rename /usr/lib/node_modules/.staging/lodash-24c8c2f4 /usr/lib/node_modules/ember-cli/node_modules/babel-core/node_modules/lodash Bareword found where operator expected at (eval 1) line 1, near "24c8c2f4" (Missing operator before c8c2f4?) Unknown regexp modifier "/b" at (eval 1) line 1, at end of line syntax error at (eval 1) line 1, near "/."

Sparticuz commented 8 years ago

Related: https://github.com/Microsoft/CommandLine-Documentation/issues/26

It seems to be an issue with symlinks

jbaribeault commented 8 years ago

Confirmed - this is totally related to the symlink issue.

jamespacileo commented 8 years ago

Same here with

npm install typescript

Here's the output

npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.
npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript" "gulp" "tsd"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! path /root/node_modules/.staging/ansi-regex-0de81b15
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename

npm ERR! Error: EACCES: permission denied, rename '/root/node_modules/.staging/ansi-regex-0de81b15' -> '/root/node_modules/ansi-regex'
npm ERR!     at destStatted (/usr/lib/node_modules/npm/lib/install/action/finalize.js:25:7)
npm ERR!     at FSReqWrap.oncomplete (fs.js:82:15)
npm ERR!
npm ERR! Error: EACCES: permission denied, rename '/root/node_modules/.staging/ansi-regex-0de81b15' -> '/root/node_modules/ansi-regex'
npm ERR!     at Error (native)
npm ERR!  [Error: EACCES: permission denied, rename '/root/node_modules/.staging/ansi-regex-0de81b15' -> '/root/node_modules/ansi-regex']
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/npm-debug.log
russalex commented 8 years ago

This looks a lot like #3. We can keep the conversation going on there.

What I can say right now is that things are getting better (at least in non-mnt directories.). On my dev box I see:

russ@RUSSALEX-DESK:~/tmp$ npm list
/home/russ/tmp
├── acorn@3.0.4
├─┬ gulp@3.9.1
│ ├── archy@1.0.0
│ ├─┬ chalk@1.1.3
│ │ ├── ansi-styles@2.2.1
│ │ ├── escape-string-regexp@1.0.5
│ │ ├─┬ has-ansi@2.0.0
│ │ │ └── ansi-regex@2.0.0
│ │ ├─┬ strip-ansi@3.0.1
│ │ │ └── ansi-regex@2.0.0
│ │ └── supports-color@2.0.0
│ ├── deprecated@0.0.1
│ ├─┬ gulp-util@3.0.7
│ │ ├── array-differ@1.0.0

It goes on from there. I should point out that I have not tried to actually use any of these, I have only installed them.

The team is hard at work getting stuff up and running. Npm is one of those things we're looking at now.

russalex commented 8 years ago

Full disclosure here. Doing a little more testing on our internal build and finding that doing an "npm -g install " still throws the uv_pipe_open error, even when in ~/tmp.

We have someone looking into it.

mablae commented 8 years ago

This seems also to be a valid issue when running npm in the new Windows 10 Bash

This solved it for me: https://gist.github.com/mattpodwysocki/4e6951fc93adae064a73ed0b2251d180

npm config set unsafe-perm true

I have no idea what it does however.

paseto commented 8 years ago

If you are using with -g option, try to remove it.

bitcrazed commented 8 years ago

FWIW, installing lodash as per the OP's request works fine on build 14931!

image

nolanlawson commented 7 years ago

I just ran into this trying to do npm install -g ember-cli/ember-cli on 15063.2. :confused:

npm config set unsafe-perm=true fixed it, but makes me uneasy.

Sparticuz commented 7 years ago

You can bypass all permission problems by changing the prefix for npm. See option 2: https://docs.npmjs.com/getting-started/fixing-npm-permissions

nolanlawson commented 7 years ago

Actually I had already set the prefix to a local user directory, and I was still getting this error.

To fully repro:

npm config set prefix="${HOME}/my-special-npm-directory"
npm install -g ember-cli/ember-cli
joeRob2468 commented 7 years ago

Hey, I just managed to fix an issue with my setup by taking ownership of the folder that Node was installed to. I use NVM to manage node versions, so in my case Node was installed in /home/myusername/.nvm.

So, to fix it, I used sudo chown -R myusername:myusername /home/myusername/.nvm. Weirdly enough, I had to run that command again each time I installed something globally, and I don't know enough to figure out why. It's a mystery!

ilyaigpetrov commented 7 years ago

The error still happens in Windows 10 Creator's Update 10.0.15063. Here is what I tried:

  1. Turn off antivirus.
  2. After npm install -g npm check that npm was actually updated (>=4.4.4). Run hash -r to update bash cache. ~/.profile is not executed in current BashOnWindows, so move all npm-related PATH modifications from ~/.profile to ~/.bashrc.
  3. Even though I set prefix for npm to directory owned/chowned by a user, I still run sudo npm install enduro -g.
  4. I get the error.
aseering commented 7 years ago

Does this happen if you don't use sudo in step 3?

ilyaigpetrov commented 7 years ago

@aseering no, it didn't work unfortunately, same rename error on node v6.10.2 and npm 4.4.4.

tinours commented 7 years ago

My anti-virus was blocking the download of packages. Thanks ilyaigpetrov.

jcserracampos commented 7 years ago

I used @Sparticuz suggested soluction and it's working fine.

flrngel commented 7 years ago

restart your bash. It seems there's some permission timeout with forked(?) process.

abunawO commented 7 years ago

Fixed this issue by putting sudo pm uninstall -g ember-cli

oldqian commented 7 years ago

npm config set unsafe-perm=true work for me, thanks

MediumRareByte commented 7 years ago

sudo npm install -g npm@5.3.0 that sorted it for me

chrisziegler commented 7 years ago

following @vinifala suggestion (reverting npm v5.4.0 to 5.3.0) fixed my recent permissions issues on Windows 10 git bash. npm install -g npm@5.3.0

Manjunath-Siddappa commented 7 years ago

try this might be useful https://askubuntu.com/questions/269727/npm-errors-when-installing-packages-on-windows-share/269735#269735?newreg=3aeb12cc6ff94c528cc50667df037070

PrincessGod commented 7 years ago

I just change my npm@5.4.1 to npm@5.3.0, it's fine now. You can use npm i -g npm@5.3.0 to downgrade.

nagarajanewlife commented 7 years ago

antoc0d3 commented 7 years ago

@nagarajanewlife npm i npm@5.3.0

giacomocerquone commented 7 years ago

On windows 10 I was trying to update dependencies in my project with npm update --save and it was returning permission errors. I tried to start the console in administrator mode but it wasn't solving the problem.

But with npm config set unsafe-perm=true it worked

lorenzosjb commented 7 years ago

I fixed this issue using npm install -g npm@next I am working on a Windows 7 pro

midsorbet commented 7 years ago

First, I tried doing sudo npm i -g npm but it did not work. Then, I tried the option 1 here and got it to work.

ilanc commented 7 years ago

Ergg... only thing that worked for me was to run my npm install in cmd.exe - couldn't get it to work in WSL bash.

bitcrazed commented 7 years ago

@ilanc - did you sudo your npm install -g ...?

efortes commented 7 years ago

I'm running node 8.8.1 This is how I managed to get this to work:

1) Start CMD.exe 2) Type bash 3) sudo npm install -g npm@5.3.0

With the normal bash i could not get this to work.

ilanc commented 7 years ago

@bitcrazed apologies for the delay. I wasn't doing global installs I was just doing a local install i.e. I was attempting to add @await/event to my package.json using npm i "@await/event" --save-dev. I kept getting EACCES errors. I tried npm cache clean - don't think I tried npm config set unsafe-perm true - and then tried the same npm command within cmd.exe and it worked.

I'm unable to repeat the problem though - I just tried to create a new project today with npm init and npm i "@await/event" --save-dev - and it worked without problems in WSL bash.

sorry I can't give you more info to help pin it down, npm does seem to be behaving a bit more erratically in WSL of late but I'm usually able to get passed it with either (1) npm cache clean or (2) running in cmd.exe - so I haven't bothered to dig too deeply.

bitcrazed commented 7 years ago

Thanks for the note. Could well be that something else in your dependency graph was trying to do something that required root, but has since been fixed to permit local installation.

For example, in the OP's case, npm returned this:

npm ERR! path /root/test/node_modules/.staging/lodash-9a2aabe2
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename

npm ERR! Error: EACCES: permission denied, rename '/root/test/node_modules/.staging/lodash-9a2aabe2' -> '/root/test/node_modules/lodash'
npm ERR!     at destStatted (/usr/lib/node_modules/npm/lib/install/action/finalize.js:25:7)
npm ERR!     at FSReqWrap.oncomplete (fs.js:82:15)

Here, the rename syscall was attempted by a process with insufficient rights, hence the EACCES error.

Let us know if you see these issues in the future, though double-check whether you have to sudo first, and/or compare the same action as a non-root user in a Linux VM.

ilanc commented 7 years ago

@bitcrazed Ah interesting. I definitely had that problem in this case too (i.e. where the npm error message says 'EACCES ... blah ... try sudo' and then you try using sudo and it just gives you the same error message).

How do I tell whether I have the fix? I assume it's a fix in WSL bash?

bitcrazed commented 7 years ago

I don't know if this applies, but I see many Mac users experiencing this issue due to macOS' different, sometimes more permissive security model vs. Linux.

This most often presents when a Mac user who authors or changes a node/npm package without realizing that their change will not work without sudo elevation on Linux.

I don't believe the fix was due to us - more likely that one of the packages was updated to eliminate this issue, though without a repro, it's hard to tell.

bradley-varol commented 6 years ago

I had this issue and it turned out to be my AV. Disabled my AV and npm install worked.

vijaybritto commented 6 years ago

I had this issue in WSL on windows. I had upgraded npm to 5.6.0 as it said there was an update available. Now I'm just using the Npm 5.5.1 that came with node 8.9.3.

So the problem seems to be updating Npm.

KadonWills commented 6 years ago

please help! how can i fix this? it gives the same error when i run the cmd as Administrator

npm ERR! path C:\Users\Kadon\AngularProjectX\node_modules\fsevents\node_modules npm ERR! code EPERM npm ERR! errno -4048 npm ERR! syscall rmdir npm ERR! Error: EPERM: operation not permitted, rmdir 'C:\Users\Kadon\AngularProjectX\node_modules\fsevents\node_modules' npm ERR! { Error: EPERM: operation not permitted, rmdir 'C:\Users\Kadon\AngularProjectX\node_modules\fsevents\node_modules' npm ERR! stack: 'Error: EPERM: operation not permitted, rmdir \'C:\Users\Kadon\AngularProjectX\node_modules\fsevents\node_modules\'', npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'rmdir', npm ERR! path: 'C:\Users\Kadon\AngularProjectX\node_modules\fsevents\node_modules' }

jazzfog commented 6 years ago

I am facing the same issue, npm config set unsafe-perm=true or node/npm upgrade didn't help.

Windows 10 (10.0.16299.309) @ WSL Ubuntu
node v9.9.0
npm 5.6.0

For instance I am trying to npm install this repo: https://github.com/jenkins-docs/simple-node-js-react-npm-app

And getting this error:

username@Username-PC:/mnt/d/web/JavaScriptApps/jenkins-test$ npm install
npm ERR! path /mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename
npm ERR! Error: EACCES: permission denied, rename '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache' -> '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/.loader-fs-cache.DELETE'
npm ERR!  { Error: EACCES: permission denied, rename '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache' -> '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/.loader-fs-cache.DELETE'
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, rename '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache' -> '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/.loader-fs-cache.DELETE'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'rename',
npm ERR!      path: '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache',
npm ERR!      dest: '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/.loader-fs-cache.DELETE' },
npm ERR!   stack: 'Error: EACCES: permission denied, rename \'/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache\' -> \'/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/.loader-fs-cache.DELETE\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/loader-fs-cache',
npm ERR!   dest: '/mnt/d/web/JavaScriptApps/jenkins-test/node_modules/.loader-fs-cache.DELETE',
npm ERR!   parent: 'my-app' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

Surprisingly Yarn is able to install dependencies.

vijaybritto commented 6 years ago

For anyone facing this issue: If you have mounted any windows folder in ubuntu so that you can use the command line functionalities and also GUI code editors through windows, this is bound to happen. Its because of some file locking rules done by windows.

So whenever this error comes up, close all the code editors or any other programs using this mounted folder in windows.

This has worked for me all the time.

jazzfog commented 6 years ago

It's hard to tell now what has fixed my issue, since I rebooted computer since then, but now it is gone. Will try IDE trick next time... thanks!

therealkenc commented 6 years ago

If you have mounted any windows folder in ubuntu so that you can use the command line functionalities and also GUI code editors through windows, this is bound to happen

This whole two year thread is #1529. The problem here is not permissions and never has been. [It is utterly unrelated to #3 which was a symlink problem, and how this one got closed.] You can install your whole NodeJS ecosystem as user yourself; you are still going to trip #1529. I asked in a related post that WSL at least throw off a (nonconforming) EBUSY so we could differentiate from actual EACESS problems but there was no response (what you gonna do).

Closing editors will help, if the thing holding open a handle is an editor. But if you take the example a couple of posts back, .loader-fs-cache is still holding a handle. No one is editing anything there. Y'all have been rebooting and discovering "works fine now", because you've closed all the handles. And the thing is you've got open handles in node in spades much of the time, because of the client-server nature of the beast.

For now you can (a) be meticulous about making sure there are no file handles open in your node universe before running npm (b) hope that your node packages get updated to be more tolerant of the problem and/or (c) wait for #1529 to flip.

BenChirlinn commented 6 years ago

@therealkenc can confirm it has to do with things being open elsewhere in your system, a pernicious and consistently annoying issue in Windows in general. At first I thought it was the ongoing node processes I had running from dev servers (I'd close them with task manager) but my latest test seems to indicate my text editor is the culprit, using Sublime Text 3. When I close it I can install modules normally.

Even adding node_modules directory to the folder_exclude_pattern and binary_file_patterns settings I still have the issue somehow. Perhaps Sublime's project implementation is touching the directories still? Not sure. Atom doesn't seem to have the same issue (but I decided against using it on Windows since it apparently can't do multi-line find replace. I just can't win[dows]!).