首页 > 解决方案 > npm install 不考虑 package-lock.json 中的注册表/解析路径

问题描述

从私有注册表安装软件包非常简单:

npm install my-package --registry https://<private-registry-url>

这将添加一个条目到package-lock.json

"my-package": {
      "version": "1.0.0",
      "resolved": "https://<private-registry-url>/<some_path>/my-package-1.0.0.tgz",
      "integrity": "sha1-Pjs/y9sEp49/OC8+8eEZFdwT3BQ="
    },

到目前为止一切顺利,一切都符合预期。

现在的问题是,当您想使用npm install. 这将失败并出现以下错误:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/my-package - Not found
npm ERR! 404
npm ERR! 404  'my-package@1.0.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'app'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<user>\AppData\Roaming\npm-cache\_logs\2019-08-06T08_33_05_103Z-debug.log

因此它尝试my-package从公共 npm 注册表 ( https://registry.npmjs.org/my-package) 中获取,但由于my-package位于私有注册表中,因此当然会失败。

现在这真的打破了我对package-lock.json.. 的理解。 npm 不应该package-lock.json查看以前的包在哪里解决吗?相反,它只是假设它必须在公共注册表中。

另一个有趣的事情是,一旦您再次手动安装带有--registry标志的软件包,它就可以工作:

npm install my-package --registry https://<private-registry-url> && npm i

之后它每次都会工作,直到您升级版本my-package或切换设备..

我也尝试了npm ci命令但没有成功(同样的错误)。

那么如何从私有注册表正确安装软件包,以便可以轻松地将它们安装在任何其他设备上使用npm install

标签: npmnpm-installpackage-lock.json

解决方案


推荐阅读