【问题标题】:I cannot publish to npm我无法发布到 npm
【发布时间】:2022-01-09 18:00:05
【问题描述】:

我正在尝试将演示按钮组件发布到 npm 并遵循此tutorial

我的 package.json

{
  "types": "dist/index.d.ts",
  "files": [
    "dist"
  ],
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/abhinav-anshul"
  },
  "name": "@abhinav-anshul/avyav",
  "version": "1.0.5",
  "description": "",
  "main": "dist/cjs/index.js",
  "module": "dist/esm/index.js",
  "scripts": {
    "rollup": "rollup -c"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@rollup/plugin-commonjs": "^21.0.1",
    "@rollup/plugin-node-resolve": "^13.1.3",
    "@rollup/plugin-typescript": "^8.3.0",
    "@types/react": "^17.0.38",
    "react": "^17.0.2",
    "rollup": "^2.63.0",
    "rollup-plugin-dts": "^4.1.0",
    "typescript": "^4.5.4"
  }
}

我的 .npmrc :

always-auth = true
registry=https://registry.npmjs.org/
@abhinav-anshul:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=<TOKEN CREATED USING GITHUB>

我的 Github repo 用于相同的here

我面临的问题是:

  1. 我已经添加了一个token并发布为“github包”,我可以看到它成功发布在我的终端上,在github包上也是如此,在repo下,它指示我做npm install @abhinav-anshul/avyav@1.0.5

  2. 但是,当我尝试完全安装在不同的项目中时,我收到的错误消息是

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@abhinav-anshul%2favyav - Not found
npm ERR! 404 
npm ERR! 404  '@abhinav-anshul/avyav@1.0.5' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
  1. 另外,我在 npmjs.org 网站上搜索包也找不到。

我不确定的事情:

  1. 是因为我的token吗?
  2. 如果某个东西作为 github 包发布,并且它确实指示我使用 npm 安装它,那么为什么它在 npmjs 站点上不可用?这是两个不同的东西吗?

任何正确方向的输入都会很有帮助。 我是第一次尝试发布一个包,如果我错过了任何明显的东西,很抱歉。

感谢您的阅读。

【问题讨论】:

  • 按照该视频教程后我面临同样的问题
  • 我确实设法修复了它,您需要将 package.json 更改为 "repository": { "type": "git", "url": "git://github.com/abhinav-anshul/avyav.git" },
  • @VikrantBhat 参考这个 repo(检查 package.json 文件)-> github.com/abhinav-anshul/avyav ,我也向 npm 发布了同样的内容

标签: node.js npm package.json github-package-registry


【解决方案1】:

该教程展示了如何将包发布到 GitHub Packages。因此,您将无法在 npmjs.org 上找到它。你可以在 GitHub 上找到your package

GitHub 于 2019 年推出了 package repository(类似于 npmjs.org)。npm(该工具)和 yarn 将从这两个存储库安装包。

如果您之前直接从 GitHub 代码存储库而不是包存储库安装此代码,您可能会收到此错误。尝试删除你的 package-lock.json 来解决这个问题。

【讨论】:

  • 非常感谢您的评论,在教程中,我检查了“tutors”仓库,该软件包可用于 npmjs 并且仍然显示在 github 软件包下。
  • 我尝试删除锁定文件,但没有成功,同样的事情
  • 我没试过,但this post 显示了如何发布到两者。
  • 使用 github 操作,与我当前的流程有点偏差。我想知道这是否是一个令牌问题。
猜你喜欢
  • 2019-06-13
  • 2018-09-25
  • 2017-01-20
  • 2021-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 2021-04-14
  • 2022-10-21
相关资源
最近更新 更多