Update npm installed packages - npm ERR! code EINVALIDPACKAGENAME
Asked Answered
S

6

14

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?

Subternatural answered 24/4, 2021 at 16:2 Comment(2)
This seems similar to issue #2835Heteronomous
@Heteronomous I've readed it but I'm unable to find the .DS_Store file anywhere. I've also enabled hidden files visualization but nothing :(Subternatural
D
12

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 )

Dumfries answered 13/10, 2021 at 8:5 Comment(1)
if you are using fnm as your node version manager and multishells, try this: find ${FNM_MULTISHELL_PATH}/lib/node_modules/ -name '.DS_Store' -type f -deleteThaothapa
D
14

I solved the same issue for Mac OS Monterey using this

find `npm list -g | head -1` -name '.DS_Store' -type f -delete
Dent answered 15/8, 2022 at 19:26 Comment(1)
This one works also if you use nvm. Thanks for it!Swiger
D
12

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 )

Dumfries answered 13/10, 2021 at 8:5 Comment(1)
if you are using fnm as your node version manager and multishells, try this: find ${FNM_MULTISHELL_PATH}/lib/node_modules/ -name '.DS_Store' -type f -deleteThaothapa
T
3

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.

Tamra answered 4/2, 2023 at 10:8 Comment(0)
A
1

You can try this one,

sudo npm install --global npm

I think this is going to work for you

Aldenalder answered 13/10, 2021 at 8:8 Comment(0)
W
1

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

Whipstock answered 3/8, 2023 at 12:32 Comment(0)
M
1

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
Metastasis answered 12/6 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.