Node.js 包未发布到npm(不在npm注册表中)

Node.js 包未发布到npm(不在npm注册表中),node.js,npm,package,Node.js,Npm,Package,我想将我的git存储库发布到npm,以便在其他项目中使用它。但是当我运行npm publish命令时,我得到以下错误: npm ERR! code E404 npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/vue-toggle-component npm ERR! 404 npm ERR! 404 'vue-toggle-component@0.1.0' is not in the npm registry. npm ERR! 4

我想将我的git存储库发布到npm,以便在其他项目中使用它。但是当我运行
npm publish
命令时,我得到以下错误:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/vue-toggle-component
npm ERR! 404
npm ERR! 404  'vue-toggle-component@0.1.0' 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!     C:\Users\niels\AppData\Roaming\npm-cache\_logs\2020-10-29T10_47_26_952Z-debug.log

在尝试修复错误时,我尝试了
npm adduser
命令和
npm login
命令以确保我已登录。这两个都没有解决我的问题,因为看起来我已经登录了

My
package.json

{
  "name": "vue-toggle-component",
  "version": "0.1.0",
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.11"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "vue-template-compiler": "^2.6.11"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ],
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },
  "description": "## Project setup ``` yarn install ```",
  "main": "babel.config.js",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/nehlis/vue-toggle-component.git"
  },
  "keywords": [
    "Vue.js",
    "Toggle",
    "component",
    "Lightweight",
    "Checkbox"
  ],
  "author": "Niels Bosman",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/nehlis/vue-toggle-component/issues"
  },
  "homepage": "https://github.com/nehlis/vue-toggle-component#readme"
}


有人知道如何解决这个问题吗?

基于
https://npm.pkg.github.com/
出现在错误输出中,您试图发布到GitHub包,而不是npm注册表(尽管GitHub现在拥有npm,但它们仍然是独立的)。根据报告:

GitHub软件包只支持作用域npm软件包。作用域包的名称格式为@owner/name。作用域包始终以@符号开头。您可能需要更新package.json中的名称才能使用作用域名称。例如,“name”:“@codertocat/hello world npm”


因此,您需要更改配置以指向npm注册表而不是GitHub软件包注册表,或者将
package.json中的
name
字段更改为作用域包名。

我也有同样的问题,问题来自于发布的包无法访问,因此您需要将
.npmrc
与您的私有repo一起添加,以实现此目的

registry=https://npm.pkg.github.com/yourcompany


尝试
npm登录
。如果出现npm publish
,有时会显示误导性信息。

另一位用户提到,您必须将自己添加到公司或组织的私人注册中心。但是,如果没有.npmrc设置,此命令将自动创建文件并更新注册表:

npm config set registry https://registry.your-company-registry.npme.io/

在.npmrc文件中添加以下代码

always-auth = true
@your_company:registry=https://npm.artifactory.your_company.com/artifactory/api/npm/npm/
registry=https://npm.artifactory.your_company.com/artifactory/api/npm/npm/
在GIT bash中执行命令

npm config set registry https://registry.npmjs.org/
npm install
屏幕截图


您到底使用了什么命令?是不是
npm-publish
?@hollyl我刚把cd放到目录中,然后运行
npm-publish
。之后就没什么了。我也分享了一个和,但我不能再帮你了:/谢谢!我这样做的同时添加了一个.npmrc文件,其中包含
注册表=https://npm.pkg.github.com/@内利斯
这对我来说很有效。
npm config set registry https://registry.npmjs.org/
npm install