npm publish causes 'Error: EPERM: operation not permitted, unlink ...', errno -4048
Asked Answered
P

7

50

I'm trying to publish my NPM package: npm publish.

I get the following quite cryptic error:

npm ERR! path c:\Temp\npm-20936-b98f84c8\tmp\fromDir-02dd5394\package.tgz
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'c:\Temp\npm-20936-b98f84c8\tmp\fromDir-02dd5394\package.tgz'
npm ERR!     at Error (native)
npm ERR!  { Error: EPERM: operation not permitted, unlink 'c:\Temp\npm-20936-b98f84c8\tmp\fromDir-02dd5394\package.tgz'
npm ERR!     at Error (native)
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, unlink 'c:\Temp\npm-20936-b98f84c8\tmp\fromDir-02dd5394\package.tgz'
npm ERR!        at Error (native)
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'unlink',
npm ERR!      path: 'c:\\Temp\\npm-20936-b98f84c8\\tmp\\fromDir-02dd5394\\package.tgz' },
npm ERR!   isOperational: true,
npm ERR!   stack: 'Error: EPERM: operation not permitted, unlink \'c:\\Temp\\npm-20936-b98f84c8\\tmp\\fromDir-02dd5394\\package.tgz\'\n    at Error (native)',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'c:\\Temp\\npm-20936-b98f84c8\\tmp\\fromDir-02dd5394\\package.tgz' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

Tried running as admin - same error.

NPM version: 5.4.0

Node version: 6.11.1

OS: Windows 10

Any leads?

Pingpingpong answered 7/9, 2017 at 7:11 Comment(1)
I just want to add that this issue can also crop up on Windows if you're utilizing a Gradle script without excluding ".gradle" within your .gitignore file...or attempting to add any sort of lock file when running the npm pack/publish command. I just chased my tail for 12 hours trying to figure that one out. See here for more info: nigglingaspirations.blogspot.com/2020/09/….Facient
P
87

Silly me. The answer was in the docs all along.

In order to publish you need to be logged in from your NPM cli.

So either do npm login if you already have a user on npmjs.com, or npm adduser to create one.

I would, however, appreciate a more informative error message.

Pingpingpong answered 7/9, 2017 at 7:11 Comment(12)
Oh GOD! It worked on my side. I was logged in long time on my main computer... But got this error, because I've changed the password, so.. Thanks! Logging in again worked!Thousand
What a terrible error message! We managed to get this working by including out private npm repo details a the .npmrc fileCabbala
I didn't find that in the docs, though it is something kind of obvious to do first.Climatology
Yes, npm login solved this problem. Misleading message information!Barmecidal
definitely a better error message is needed! I just struggled a bit with this on a new PC :)Climatology
I get this error when trying to publish a scoped package to our organization's repository (VSTS) not to npm.Gangrene
How is this related to a permission error when attempting to delete a folder?Vying
@Vying - the correlation is not entirely clear to me as well. A better error log is definitely needed.Pingpingpong
@vaiden the syscall unlink means a deletion of a file or directory is attempted.Vying
@Vying yeah but I'm not clear on the correlation with the authentication (login) status.Pingpingpong
Neither do I. Moreover, I don't think it is related to login at all. I think something is locking the file or directory. Possibly the IDE or my employer's antivirus.Vying
In most people's case - it is due to the authentication. A login solves it in the majority of cases.Pingpingpong
K
2

I had the same problem on Windows.

The source of the problem is simple, it is access permission on folders and files. Click here

Kamat answered 8/12, 2018 at 17:5 Comment(0)
Z
1

Here is my experience.

I was working on Atom, and did file drag drop on Atom, it cause error. So I exit atom on Win10 and run npm i again. It was successful.

Please turn off your editor or explorer which can restrict your project files and try again.

Zackaryzacks answered 27/3, 2019 at 16:52 Comment(0)
O
0

I changed to the new filesystem by remounting my windows drives. After that no problems anymore. Refer to the following link.

Orchestrate answered 3/7, 2019 at 13:20 Comment(0)
M
0

In some cases it is a matter of pointing to the correct package.json file. Had omitted the param in the before, causing the error.

Before: npm publish

After: npm publish C:\Code\my-proj\dist\@acme\my-package

Mcleod answered 23/10, 2019 at 19:49 Comment(0)
W
0

People who are still struggling, check your package.json file if you have something like publishConfig initialized.
Deleting this is what solved for me

Westbound answered 21/2, 2021 at 11:0 Comment(0)
C
0

In my case problem was incorrect param npm publish --opt=123456 (typo opt => otp ... one time password - 2factor). Terrible this misleading permission error The operation was rejected by your operating system. in case of wrong params.

Chromatic answered 25/11, 2021 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.