简体   繁体   中英

Couldn't find package “my-custom-package” on the “npm” registry

I have a Node.js project separated in several custom packages, each having their own package.json file. This is all custom code for that specific project. Some have dependencies/devDependencies , and when running

yarn install

all dependencies are installed and everything goes smoothly.

The content of the package.json files are as follows:

{
  "name": "my-custom-package-name", // This changes in each package.json file
  "version": "1.0.3-beta.1", // The version is the same in all package.json files
  "private": true,
  "repository": "https://github.com/my-organization/my-private-repo",
  [...]
}

Now I am asked to do a new deployment of the project to production and to increment the version number of the packages for the new release. So I change the version number in each package.json file by removing the prerelease tag to:

"version": "1.0.3.1"

But then, if I run yarn install again, for each package where the prerelease tag was removed from the version number of the custom package, I get an error like this:

yarn install v1.3.2
[1/4] Resolving packages...
error Couldn't find package "my-custom-package-name" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Why is this happening when the prerelease tag is removed? Why is this not happening when the prerelease tag is there?

Those packages are not being used as dependencies for any other package of the project, so why is yarn trying to resolve a package on npm that matches the name and version of the package.json files?

I really looked around on the Web trying to find answers relating to this, but could not find anything relevant.

I found the answer to my problem and the reason is that by removing the "-beta" from the version number, the version number no longers complies with sematinc versioning. See this other SO question here:

npm: Why is a version "0.1" invalid?

In other words, version number must be 3 numbers separated by dots, and after that a dash can be put with a prerelease tag or a build number. But having a version number composed of 4 digits separated by dots is not a valid version number according to semver.org.

So for some reason, instead of complaining of an illegally formatted version number for my package, "error Couldn't find package" is what yarn outputs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM