newbiedev
newbiedev

Reputation: 3586

Update npm installed packages - npm ERR! code EINVALIDPACKAGENAME

I'm trying to update my node modules globally. I'm using this command

sudo npm update -g 

but it will produce thise error in terminal

npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name ".DS_Store": name cannot start with a period

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/dev/.npm/_logs/2021-04-24T15_59_25_014Z-debug.log

I think that the command will scan the folder and find macOS .DS_Store file.

How I can fix this?

Upvotes: 15

Views: 9807

Answers (6)

Robert
Robert

Reputation: 2824

it happened with me because of corrupted package-lock.json, the package name was actually non-existing

so a possible resolution will be to delete package-lock.json and run npm i

corruption can happen in package-lock.json for 3 reasons

  1. internet instability during npm i
  2. git conflicts
  3. global find and replace in a project

Upvotes: 1

joseph Musinga
joseph Musinga

Reputation: 11

For Windows, an alternative

I was getting the error with the mime-type;s package:

npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name "mime-type;s" of package "mime-type;s@~2.1.34": name can only contain URL-friendly characters.

I resolved this by deleting the line with the module name mime-type;s inside the project package-lock.json file since I could not find mime-type;s in either C:\Users\<username>\AppData\Roaming\npm\node_modules and C:\Program Files\nodejs\node_modules\. directories

Upvotes: 1

Саша Черных
Саша Черных

Reputation: 2813

1. Solution

For Windows users.

Delete the folder with the incorrect name.

I have it at the address:

C:\Program Files\nodejs\node_modules

According to Laertes Moustakas (at the time of writing my answer, his GitHub comment has 9 likes), the folder with the incorrect name may be located at the different address:

C:\Users\<username>\AppData\Roaming\npm\node_modules

2. My example

I was getting the error:

D:\SashaDebugging>npm update -g
npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name ".corepack-yRBjKBW1" of package ".corepack-yRBjKBW1@*": name cannot start with a period.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SashaChernykh\AppData\Local\npm-cache\_logs\2023-02-04T06_33_17_981Z-debug-0.log

I deleted the folder:

C:\Program Files\nodejs\node_modules\.corepack-yRBjKBW1

Now I can successfully update my npm packages:

D:\SashaDebugging>npm update -g

added 180 packages, removed 236 packages, and changed 2338 packages in 36m

369 packages are looking for funding
  run `npm fund` for details

3. My environment

  1. Microsoft Windows [Version 10.0.19041.1415]
  2. Node.js 19.6.0
  3. npm 9.4.1

4. Disclaimer

This answer is relevant for February 2023. In the future, its data may be outdated.

This solution may not work on a different environment.

Upvotes: 4

Silicon Socket
Silicon Socket

Reputation: 221

I solved the same issue for Mac OS Monterey using this

find `npm list -g | head -1` -name '.DS_Store' -type f -delete

Upvotes: 16

Umac
Umac

Reputation: 136

for me doing this solve my problem :

find /usr/local/lib/node_modules/ -name '.DS_Store' -type f -delete 

It search all .DS_Store and remove it in the global node_modules folder ( on Mac )

Upvotes: 12

Emad Baqeri
Emad Baqeri

Reputation: 2702

You can try this one,

sudo npm install --global npm

I think this is going to work for you

Upvotes: 1

Related Questions