私有存储库的作用域 NPM 将斜杠“/”转换为“%2F”

问题描述 投票:0回答:6

我想使用范围从私有存储库获取私有 npm。 我已将 .npmrc 设置为这样。

registry=https://registry.npmjs.org/
@myco:registry=https://nexus.myco.com/nexus/repository/

我已经这样设置了 .yarnrc 。

registry "https://registry.npmjs.org/"
"@myco:registry" "https://nexus.myco.com/nexus/repository/"

但是当我这样做时:

yarn --verbose add @myco/some-private-npm

它抛出此错误:

verbose 0.708 Performing "GET" request to "https://nexus.myco.com/nexus/repository/@myco%2fsome-private-npm".
verbose 0.792 Request "https://nexus.myco.com/nexus/repository/@myco%2fsome-private-npm" finished with status code 404.

当我这样做时:

 yarn --verbose add @myco:some-private-npm

它会转到这个 400 url(Nexus:无效的存储库路径):

verbose 0.957 Request "https://nexus.myco.com/nexus/repository/@myco:some-private-npm" finished with status code 400.

实际的 npm 位于:

https://nexus.myco.com/nexus/repository/myco/some-private-npm

如何确保获取的网址不包含“@”且“%2f”是“/”?

谢谢!

node.js npm nexus
6个回答
1
投票

针对纱线的这个 github 问题,尝试将类似的配置添加到您的 .yarnrc 中:

registry "https://registry.npmjs.org/"
"@myco:registry" "https://nexus.myco.com/nexus/repository/"

如果失败,我建议仔细阅读链接的问题并尝试提供的解决方案。


1
投票

我前段时间遇到了完全相同的问题。 检查 NPM 您的存储库团队访问级别是否为读/写。 在我这边,我所在的团队只有读取访问级别。切换解决了问题。


0
投票

另一种可能的情况是斜杠编码并不是真正的问题。您根本无权访问该特定存储库。

这可以解释 404,因为如果出于安全原因您没有访问权限,就好像它不存在一样,您不会收到 401。


0
投票

我在尝试在 Github Actions 中运行 .tgz 文件的

npm publish
时找到了此页面,并获得以下内容(替换的范围和包):

npm ERR! 404 Not Found - PUT https://registry.npmjs.org/@SCOPE%2fPACKAGE - Not found
npm ERR! 404 
npm ERR! 404  '@SCOPE/[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

此包IS已发布,因此我认为 %2f 导致了该问题。我也使用 NPM_TOKEN 作为环境变量,根据 npmjs 文档

解决方案:

      - name: Setup Node.js environment
        uses: actions/[email protected]
        with:
          node-version: '12'
          registry-url: 'https://registry.npmjs.org'
        
      - name: Publish to npmjs
        run: |
          npm install
          npm run pack
          npm publish <package tgz> --access public
        env:
          NPM_TOKEN: ${{ secrets.NPM_APIKEY }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_APIKEY }}

通过 Github 文档

注意:我不确定这里是否还需要 NPM_TOKEN。


0
投票

确保 .yarnrc 实际上包含 注册表“https://registry.npmjs.org/” 并不是 注册表“registry.npmjs.org” 这会给出同样的错误。


0
投票

对我来说,问题是我不符合 GitLab 命名约定

我的范围内有大写字母。

© www.soinside.com 2019 - 2024. All rights reserved.