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
- Microsoft Windows [Version 10.0.19041.1415]
- Node.js 19.6.0
- 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.
.DS_Store
file anywhere. I've also enabled hidden files visualization but nothing :( – Subternatural