Reputation: 3586
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
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
npm i
Upvotes: 1
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
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
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
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
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
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
Reputation: 2702
You can try this one,
sudo npm install --global npm
I think this is going to work for you
Upvotes: 1