在本地注册表域中发布模块时,如何安装npm依赖模块?

时间:2018-07-24 10:44:42

标签: javascript node.js npm

我有一个模块,该模块已在我的自定义注册域中发布。 http://my-custom-npm-registry.com,然后我可以在其中发布模块。 我对发布模块中的依赖项有疑问,例如。

"dependencies": {
    "angular2-text-mask": "^8.0.3"
},

尝试安装我的已发布模块,如

npm install my-published-module --save --registry=http://my-custom-npm-registry.com

我遇到错误

npm http fetch GET 404 registry=http://my-custom-npm-registry.com/angular2-text-mask 170ms

似乎npm试图从我的注册表域中获取依赖项模块,但找不到解决方案来解决它。

如何在脚本中添加检查以查看注册表中是否有类似依赖模块的模块尝试安装它,如果没有尝试从npm“ https://registry.npmjs.org/”的全局注册表中安装呢?

2 个答案:

答案 0 :(得分:0)

对我来说,我将像往常一样将注册表设置为npm https://registry.npmjs.org/的全局注册表。然后从我自己的注册表中安装我的自定义软件包。像这样:

=

模块的url可能有所不同,具体取决于您在服务器上存储模块的方式。

第二种可能性是使用https://github.com/rlidwka/sinopia部署私有注册表。它将自动将公共软件包代理到npmjs.org。

希望这会有所帮助。

答案 1 :(得分:0)

根据您的评论,您可以从自定义域模块中获取某些或特定的程序包,而其余模块可以来自npm服务器,如:

"dependencies": {
    "prop-types": "^15.5.10",
    "react-click-outside": "git+https://github.com/pranavq212/react-click-outside.git",
    "my-published-module": "http://my-custom-npm-registry.com/angular2-text-mask"
}

确保http://my-custom-npm-registry.com/angular2-text-mask路径存在,并且软件包模块需要编译的文件

现在不要在--registry中使用npm install标签。

使用npm install my-published-module --save