私有 npm 注册表的 npm 安装失败

npm install of private npm registry is failing

我已经使用 gitlab 创建了一个私有的 npm 注册表

我有以下 .npmrc 文件,它与我用来发布的相同 .npmrc 文件没有问题。我用占位符替换了所有公司值。

@myorg:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=[[MY_TOKEN_HERE]]
//gitlab.com/api/v4/projects/12345678/packages/npm/:_authToken=[[MY_TOKEN_HERE]]

我在安装时收到以下错误消息

npm install @myorg/my-package-name-here
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@myorg/my-package-name-here - Not found
npm ERR! 404
npm ERR! 404  '@myorg/my-package-name-here@latest' 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:

这对我来说似乎没有获取 .npmrc 文件,因为注册表不同。

我已经检查过,文件肯定是 .npmrc 而不是不同的扩展名等等。

有人有什么想法吗?

编辑

我做了一些调查,看起来确实有人在使用我的 .npmrc 文件,但是注册表

'https://gitlab.com/api/v4/packages/npm/@myorg/my-package-name-here'

正在重定向到

'https://registry.npmjs.org/@myorg/my-package-name-here'

这就是为什么它将显示为...

它没有向我解释为什么使用我以前发布的身份验证令牌等找不到它?

我想通了...

一切正常,除了 @myorg 与我的 gitlab 组织名称不匹配。

例如gitlab url 是这样的:

https://gitlab.com/my-company/...

相反,它需要匹配github url,所以在上面的例子中

@my-company

切换后一切正常,我可以获得 npm 包。

范围名称“需要匹配 github [原文如此] url”(相信 github 的意思)不一定正确(如已接受的答案中所述)成为 GitLab)。

使用 GitLab,范围名称可能与 GitLab 的根目录不匹配 URL。

区别在于注册表在项目(或用户).npmrc.

中的配置方式

来自 GitLab:

When you use the instance-level endpoint, only the packages with names in the format of @scope/package-name are available. For example, if your project is https://gitlab.example.com/my-org/engineering-group/team-amazing/analytics, the root namespace is my-org. When you publish a package, it must have my-org as the scope.

实例级端点的注册表配置如下所示:

@scope:registry=https://gitlab.com/api/v4/packages/npm/

...但是,如果您的作用域名称与 GitLab URL 的根目录不匹配,您将需要一个 项目级 端点配置:

@scope:registry=https://gitlab.com/api/v4/projects/<your_project_id>/packages/npm/.

https://docs.gitlab.com/ee/user/packages/npm_registry/index.html

我的分分助人。

当您创建要处理 Package Registry 的存储库时,您已经在 group 或您自己的 user 中创建了。观察创建它的位置非常重要。可能您的注册表存储库 url 是这样的:

https://your.gitlab.com/{name_of_group_or_name_of_user}/[{optional_subgroup}/]{repository_registry_name}

现在,假设您在 url 中有一个包裹:

https://your.gitlab.com/my-group/my-package

而 url registry 是:

https://your.gitlab.com/main/registry

my-package@scope 需要 @main/my-package,而不是 @my-group/my-package。如果你在这里定义错误的 @scope,它会给你 404.

my-package:

{
    "name": "@main/my-package",
     ...
}

@scope 是注册表存储库路径 url 的第一段。