Skip to main content

npm publish errors with "npm error 402 Payment Required"

When publishing a package for the first time, you might encounter an error like this:

npm error code E402
npm error 402 Payment Required - PUT https://registry.npmjs.org/@rbxts%2fpackage - You must sign up for private packages

This happens because if you're publishing to a new package to an organization, it's private by default. However, private packages require a paid npm org (which we don't have).

There are two ways to fix this issue:

1. package.json publishConfig setting

Add the following to your package.json.

{
"name": "@rbxts/package", // your package name goes here
"version": "1.0.0",
"publishConfig": {
"access": "public"
}
// other fields
}
note

If you're using the npm init roblox-ts package command, this will be done for you automatically.

2. npm publish CLI flag

npm publish --access public