403 Forbidden when publishing subdirectory
Description
I think this may only affect npm v7, but I've found that when publishing, I have started to get an error at the publish step:
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/dist - You do not have permission to publish "dist". Are you logged in as the correct user?
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.
As you can see, it's not trying to publish the dist subdirectory but a package called "dist" which I do not own. The workaround (or solution?) is to use a relative path, details below.
Steps to reproduce
npconfig:
{
"np": {
"yarn": false,
"contents": "dist"
}
}
- I have also added a step that copies the README and package.json to the
distdirectory so that consumers can import from the root of the module. This probably doesn't affect anything but thought I should disclose all tweaks.
{
"scripts": {
"postversion": "cpy README.md dist/ && cpy package.json dist/"
}
}
Expected behaviour
np publishes without error.
Workaround / solution?
Maybe this is the solution and we don't need a fix 🤷♂️ Use a relative path:
{
"np": {
"yarn": false,
"contents": "./dist"
}
}
Environment
np - 7.4.0 Node.js - 15.9.0 npm - 7.5.4 Git - 2.24.3 OS - macOS 11.2.1
PS
Thank you for this project! It takes a lot of hassle out of npm publishing.
I think having relative path makes sense. Even the normal imports in node works with ./. Keeping this this way would the easiest and straight forward solution for me.
I have the same issue. it used to work and now i'm on another computer and getting this error..
I don't even remember what's contents for.. The README (docs) does not explain well enough. I already have files property in the package.json file, so why would I need contents..?
I simply removed contents from the np property object in package.json file and now things work as they should.