Nodejs npm publish上个月error之后一直没好

Nodejs npm publish上个月error之后一直没好

ERR! registry error parsing json
ERR! registry error parsing json
ERR! registry error parsing json
ERR! publish Failed PUT 500
ERR! SyntaxError: Unexpected token A
ERR! An internal server error occurred. Please try again later
ERR!     at Object.parse (native)
ERR!     at RegClient.<anonymous> (C:\Program Files\nodejs\nod
.js:240:23)
ERR!     at Request.callback (C:\Program Files\nodejs\node_mo
212:65)
ERR!     at Request.self.callback (C:\Program Files\nodejs\nod
ERR!     at Request.emit (events.js:98:17)
ERR!     at Request.<anonymous> (C:\Program Files\nodejs\node
ERR!     at Request.emit (events.js:117:20)
ERR!     at IncomingMessage.<anonymous> (C:\Program Files\node
)
ERR!     at IncomingMessage.emit (events.js:117:20)
ERR!     at _stream_readable.js:929:16
ERR! If you need help, you may report this entire log,
ERR! including the npm and node versions, at:
ERR!     <http://github.com/npm/npm/issues>

顺便问一下cnpm怎么publish 兄弟们,帮帮忙吧,一个月没更新了。 我的package.json文件

{
  "name": "jdtpl-generator",
  "version": "0.2.7",
  "description": "a tool to generator project file system",
  "scripts": {
    "test": "mocha --reporter spec --bail --check-leaks test/",
    "test-travis": "mocha --reporter spec --bail --check-leaks test/"
  },
  "keywords": [
    "generator",
    "jdtpl"
  ],
  "author": {
    "name": "wuwei"
  },
  "license": "MIT",
  "dependencies": {
    "commander": "1.3.2",
    "mkdirp": "0.3.5"
  },
  "preferGlobal": true,
  "bin": {
    "tpl": "./bin/tpl"
  },
  "devDependencies": {
    "mkdirp": "~0.3.5",
    "mocha": "~1.21.4",
    "rimraf": "~2.2.8",
    "should": "~4.0.4",
    "supertest": "~0.13.0"
  },
  "engines": {
    "node": ">= 0.8.0"
  },
   "files": [
    "LICENSE",
    "bin/",
    "template/",
    "test/"
  ],
  "readme": "xxxxxx",
  "readmeFilename": "README.md"
}

7 回复

根据你提供的错误日志和 package.json 文件内容,可以推测你在使用 npm publish 命令时遇到了一些问题。这些错误信息表明你在尝试发布包时遇到了服务器端的问题,具体来说是解析 JSON 数据时出现了错误。

问题分析

从错误日志来看,你遇到的错误可能是由于以下几个原因导致的:

  1. 网络问题:你的网络可能不稳定或者与 npm 服务器之间的连接存在问题。
  2. 服务器端问题:npm 服务器本身可能存在一些临时性的问题。
  3. 客户端问题:你本地的 npm 客户端配置可能有问题,或者某些依赖项的版本不兼容。

解决方案

1. 检查网络连接

确保你的网络连接稳定,并且能够正常访问 npm 服务器。

ping registry.npmjs.org

2. 更新 npm 版本

确保你使用的是最新版本的 npm,因为旧版本可能存在一些已知的问题。

npm install -g npm

3. 清除 npm 缓存

有时候缓存中的数据可能导致问题,清除缓存后重新尝试发布。

npm cache clean --force

4. 检查 package.json 文件

确保 package.json 文件没有语法错误,并且所有依赖项的版本都是正确的。

{
  "name": "jdtpl-generator",
  "version": "0.2.7",
  "description": "a tool to generator project file system",
  "scripts": {
    "test": "mocha --reporter spec --bail --check-leaks test/",
    "test-travis": "mocha --reporter spec --bail --check-leaks test/"
  },
  "keywords": ["generator", "jdtpl"],
  "author": { "name": "wuwei" },
  "license": "MIT",
  "dependencies": {
    "commander": "1.3.2",
    "mkdirp": "0.3.5"
  },
  "preferGlobal": true,
  "bin": { "tpl": "./bin/tpl" },
  "devDependencies": {
    "mkdirp": "~0.3.5",
    "mocha": "~1.21.4",
    "rimraf": "~2.2.8",
    "should": "~4.0.4",
    "supertest": "~0.13.0"
  },
  "engines": { "node": ">= 0.8.0" },
  "files": ["LICENSE", "bin/", "template/", "test/"],
  "readme": "xxxxxx",
  "readmeFilename": "README.md"
}

5. 使用 cnpm 发布

如果你希望使用 cnpm 来发布包,首先需要安装 cnpm

npm install -g cnpm --registry=https://registry.npmmirror.com

然后你可以使用 cnpm publish 命令来发布你的包:

cnpm publish

总结

以上步骤可以帮助你解决 npm publish 失败的问题。如果问题仍然存在,建议查看 npm 的官方文档或向社区寻求帮助。


你自己 json 写错了吧😒

借帖子也问个 npm publish 的问题,已经 npm publish 了新版本, npm install 强制版本号可以安装新版,但是 npm 的插件页面不更新,还是 0.0.1, npm install 不限制版本号时安装的也是旧版本。

第一次 publish ,请问是那个环节出了问题呢?

btw,已经升级三天 但没有更新了

难道大家的npm publish都没问题么,再也不想复制黏贴了

对不起大家,因为我改密码了,但是错误提示也太扯淡了

根据你的描述,错误信息表明在尝试使用 npm publish 命令时遇到了服务器解析 JSON 的问题。这可能是由于多种原因造成的,比如网络不稳定、npm 服务端问题或者你的 package.json 文件有问题。

解决步骤

  1. 检查网络连接:确保你的网络连接正常,可以访问 npm 服务器。
  2. 更新 npm 版本:有时旧版本的 npm 可能会遇到兼容性问题。可以尝试更新 npm 到最新版本。
    npm install -g npm[@latest](/user/latest)
    
  3. 检查 package.json:确认你的 package.json 没有语法错误。
  4. 清除 npm 缓存:清除 npm 缓存有时也能解决问题。
    npm cache clean --force
    
  5. 重试:在排除以上可能问题后,再次尝试发布。

示例代码:更新 npm 并清除缓存

# 更新 npm
npm install -g npm[@latest](/user/latest)

# 清除 npm 缓存
npm cache clean --force

# 尝试重新发布
npm publish

如果上述步骤仍然无法解决你的问题,建议查看 npm 的官方文档或 GitHub Issues 页面寻求帮助。

关于 cnpm

cnpm 是一个由淘宝团队维护的 npm 镜像,如果你在中国,可能会因为网络原因导致直接访问 npm 速度慢或失败。你可以安装并使用 cnpm:

npm install -g cnpm --registry=https://registry.npmmirror.com

然后用 cnpm 来代替 npm 的命令:

cnpm publish

这样可能会提升你的发布速度和成功率。

回到顶部