Installation with npm fails but npx works

37 Views Asked by At

On windows on a command prompt with local admin rigths i tried

  • npm install jasmine but it fails to install
  • to my surprise npx jasmine init did work

See command output below. For other packages the error is the same

  • npm i @redocly/cli fails
  • but npx @redocly/cli lint path-to-root-file.yaml did work

Question

  • What could be the cause? How to fix it?
  • What other workarounds do exist?

Command output

Running npm install jasmine or any other package results in

C:\dev\jasmine>npm install jasmine
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\'
npm ERR!  [Error: EPERM: operation not permitted, mkdir 'C:\'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'C:\\'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use 
         (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please 
         double-check the npm ERR! permissions of the file and its 
         containing directories, or try running
         the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: 
         C:\Users\<myuser>\AppData\Local\npm-cache\_logs
                    \2024-03-01T08_55_48_109Z-debug-0.log

running npx init jasmine works and outputs

C:\dev\jasmine>npx jasmine init
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
npm notice Beginning October 4, 2021, all connections to the npm
           registry - including for package installation - must 
           use TLS 1.2 or higher. You are currently using plaintext
           http to connect. Please visit the GitHub blog for more 
           information: 
           https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm 
           registry - including for package installation - must 
           ... as above
0

There are 0 best solutions below