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

node.jsNpmNpm PublishNpmjs

node.js Problem Overview


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?

node.js Solutions


Solution 1 - node.js

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.

Solution 2 - node.js

I had the same problem on Windows.

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

Solution 3 - node.js

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.

Solution 4 - node.js

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

Solution 5 - node.js

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

Solution 6 - node.js

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

Solution 7 - node.js

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVaidenView Question on Stackoverflow
Solution 1 - node.jsVaidenView Answer on Stackoverflow
Solution 2 - node.jsThiago SilvaView Answer on Stackoverflow
Solution 3 - node.jssmartworld-dmView Answer on Stackoverflow
Solution 4 - node.jsLemonView Answer on Stackoverflow
Solution 5 - node.jsSushiGuyView Answer on Stackoverflow
Solution 6 - node.jsVishal AroraView Answer on Stackoverflow
Solution 7 - node.jsmikepView Answer on Stackoverflow