npm ERR! This package has been marked as private

Viewed 3371

I try to publish my angular library on npm.

But i get error

npm ERR! This package has been marked as private. Remove the 'private' field from the package.json to publish it.

But i don't have any private field in my package.json file

My package.json file of my library looks like this:

{
  "name": "@myfirst_mylastname/testlib123",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^11.1.2",
    "@angular/core": "^11.1.2"
  },
  "dependencies": {
    "tslib": "^2.0.0"
  },
  "description": "Test library",
  "author": {"name":"test name"},
  "keywords": ["test library"],
}

what i tried

I thought that private is always by default and i added "private":"false" to my package.json file but i get same error on npm publish.

I googled and i found answers where they say - make private field true or false in the package.json file. I tried that but without success

Why is that ? How can be solved ?

1 Answers

In case this is a problem for anyone else, the error thrown by NPM when publishing a scoped package is misleading.

There may be no "private" field in your package.json file, however scoped packages have their access property set to restricted by default, whereas normal packages are public by default (https://docs.npmjs.com/cli/v8/commands/npm-publish#access).

To be able to publish your scoped package, ensure first that your terminal is in the root of the package - the publish command only affects the directory that you are in. Then use a flag to set its access property when publishing:

npm publish --access=public

You should also be able to set the default access value for your package using the command

npm access public @myfirst_mylastname/testlib123

which would allow you to publish without specifying the flag. (https://docs.npmjs.com/cli/v8/commands/npm-access#details)

Related