primers

Although I have published packages before, I have never released my own package, so I tried it with the NPM Developer Guide and got the following results.

403 Forbidden

After registering for the login, the library is ready, and then NPM publish reports the following error:

Error: 403 Forbidden – PUT registry.npmjs.org/xx – You do not have permission to publish “xx”. Are you logged in as the correct user?

After checking the information, I found this issue. It turned out that there was already a library with the same name in the public library. Since it is a free account, if you want to distribute packages on NPM, either change the name or pay to create a private package. Another way is to build your own service on the Intranet.

Error: 402 Payment Required

I changed the name and remembered the library I had seen before, so I copied the package with @ prefix and republished it with the following error:

Error: 402 Payment Required – PUT registry.npmjs.org/@xx/xx – You must sign up for private packages

NPM publish: @npm/package-name: @npm/package-name: @npm/package-name: @npm/package-name: @npm/package-name: @npm/package-name: @npm/package-name: @npm/package-name Therefore, the first way is to pay for the services of the private package, and the other way is to specify parameters that represent the public:

npm publish --access public
Copy the code

Note that the package name in this form corresponds to the NPM account and cannot be filled in casually.

npm init --scope=@my-org
Copy the code

This form represents an organization, and my-org corresponds to the organization name in NPM.

npm init --scope=@my-username
Copy the code

This form represents a person, and my-username corresponds to the username in NPM.

Disposal of old packages

In the process of trying, some packages were released, thinking they were just test packages and trying to remove them, but NPM officials deprecated this and recommended using the NPM Deprecate directive to inform the installer of relevant information, such as “I no longer maintain this library, please do not use it”.

npm deprecate package-name "This is test package, do not use it!"
Copy the code

Where package-name refers to the name of the published package, which may be different from the name of the library.

The release was successful, but the package could not be found on NPM

In a release, a message indicating that the release was successful was displayed, but the NPM account found no related package.

Repeatedly tried several times to find because their local registry to the Intranet of an address, no point to NPM’s official address at https://registry.npmjs.org/.

So when sending a package, first make sure to release the direction:

NPM config Get Registry or NPM config ListCopy the code

If the reference is found to be incorrect, there are two ways to change it: Method 1: use NPM config set Registry to change the reference, but this is a global change, and then change it back if you need to publish other reference packages.

Option 2: Add the –registry parameter to the package.json file:

"publishConfig": { "registry": "https://npm.pkg.github.com/" }
Copy the code

When logging in, add the corresponding parameters:

npm login --registry=https://registry.npmjs.org/
Copy the code

When using the NPM DEPRECate directive, you also need to add the –registry parameter to be valid if the local Registry does not point correctly.

How do I determine whether the NPM account is logged in

Since published packages have different Registry points, logins point to different sources when publishing packages, so you want to see if you are logged in before publishing.

I looked at the documentation and found no specific command for viewing login status, but you can use commands that trigger a login check to see if you are logged in from the side.

It’s easy to think of the NPM login command, but after logging in once, you are prompted for your account and password.

A simple command, NPM whoami, was discovered. This command can only be executed in the login state, and if there is no login, it will prompt:

npm ERR! code ENEEDAUTH

npm ERR! need auth This command requires you to be logged in.

npm ERR! need auth You need to authorize this machine using npm adduser

Note that this directive without the registry parameter points to the NPM default Registry, and if this does not match, it will have no effect.

When there are multiple Registries, it is important to note that many directives require a consistent Registry to be valid.

The resources

  • npm help docs
  • Creating and publishing scoped public packages
  • npm-deprecate
  • npm-config

The German philosopher Max Weber divided rationality into two types: value rationality and instrumental rationality.

In short, we’re thinking why make money? What kind of life is happiness? When it comes to this kind of problem, the kind of rationality that we rely on is called value rationality. The reason we use when we consider the purpose of doing something is a value reason.

What is the most effective, energy saving and cost effective way to achieve a goal is instrumental rationality.

Max Weber once put forward that a very important crisis in modern society is that instrumental rationality will overtake value rationality in the whole process of modernization. Simply put, we end up forgetting why we live and why we go to work.

When I saw this, I was really in a daze, which well explains some of the numbness.