我正尝试在gitlab私有实例上使用我的第一个私有npm包
我在.npmrc中添加了@ajouve:registry=https://gitlab.my-website.io/api/v4/packages/npm/
命令npm get似乎返回了正确的配置
; "project" config from /Volumes/Work/service/.npmrc
@ajouve:registry = "https://gitlab.my-website.io/api/v4/packages/npm/"
; "cli" config from command line options
omit = []
user-agent = "npm/7.5.4 node/v12.18.1 darwin x64"
; node bin location = /usr/local/bin/node
; cwd = /Volumes/Work/service
; HOME = /Users/ajouve
; Run `npm config ls -l` to show all defaults.但是当我想要添加包的时候
npm install --save @ajouve/my-module
我有过
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@ajouve/my-module Not found
npm ERR! 404
npm ERR! 404 '@ajouve/my-module@*' 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
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! /Users/ajouve/.npm/_logs/2021-03-19T15_06_50_186Z-debug.log运行npm config ls -l | grep registry
我有过
metrics-registry = "https://registry.npmjs.org/"
registry = "https://registry.npmjs.org/"
@ajouve:registry = "https://gitlab.my-website.io/api/v4/packages/npm/"发布于 2021-03-23 15:20:32
使用git+ssh://而不是git://
npm i -S git+ssh://git@gitlab.com:<org>/<project>.git在这里你可以得到几个答案
发布于 2021-03-26 21:29:14
作为几天前开始使用Gitlab注册表的人,我也遇到了同样的问题。在.npmrc上,范围名称必须与您的数据包范围一致。例如,如果我们有一个项目A,它的package.json应该是这样的:
{
"name": "@myscope/myproject",
...Rest of your package.json在您的项目B上,.npmrc必须与作用域匹配
@myscope:registry=https://gitlab.com/api/v4/packages/npm/然后,确保您使用作用域注册表进行了身份验证,否则NPM将抛出错误或忽略并在NPM注册表上进行搜索
$ npm config set @myscope:registry https://gitlab.com/api/v4/packages/npm/
$ npm config set -- '//gitlab.com/api/v4/packages/npm/:_authToken' "<your_token>"注意:应该是在您的Gitlab配置文件上创建的访问令牌。您可以通过进入Preferences > Access Tokens来创建它。确保在创建令牌之前勾选"read_registry“。
然后,您就可以轻松地安装您的软件包了
$ npm install --save @myscope/myproject编辑:如果您使用的是自托管的gitlab实例,它遵循相同的规则,只需记住将"gitlab.com“更改为您的gitlab实例url即可。
发布于 2021-03-22 12:50:05
试试这个,应该行得通。
npm install --save @ajouve/my-module --registry=https://gitlab.my-website.io/api/v4/packages/npm/ 另一种方法是在私有实例中创建组端点,它将hosted + proxy指向公共包,并更新注册表以指向该端点,这样私有包和公共包都可以工作。
https://stackoverflow.com/questions/66710861
复制相似问题