您的当前位置:首页正文

npm publish 发布自己的npm包

来源:华拓网

官网的发布写的比较简单,直接就是npm pulish .但实际上直接运行这个命令很可能报错。
正确的发布顺序是:

1.初始化 package.json

npm init

2.验证你在 npmjs.org 上的账号

npm adduser

3.发布

npm publish .

4.安装

npm install XXX --save

版本号规范

主版本号:当你做了不兼容的 API 修改,
次版本号:当你做了向下兼容的功能性新增,
修订号:当你做了向下兼容的问题修正。

先行版本号及版本编译信息可以加到“主版本号.次版本号.修订号”的后面,作为延伸。

问题

问题1

no_perms Private mode enable, only admin can publish this module

那么可能是你用了国内的镜像地址了,只需要重新把地址注册回npmjs即可。

npm config set registry http://registry.npmjs.org

返回淘宝镜像

npm config set registry https://registry.npm.taobao.org

问题2

npm ERR! you do not have permission to publish "your module name". Are you logged in as the correct user?

Package.json格式

{
  "name": "my_package",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "ag_dubs",
  "license": "ISC",
  "repository": {
    "type": "git",
    "url": 
  },
  "bugs": {
    "url": 
  },
  "homepage": 
}

name: defaults to author name unless in a git directory, in which case it will be the name of the repository
version: always 1.0.0
main: always index.js
scripts: by default creates a empty test script
keywords: empty
author: whatever you provided the CLI
license: [ISC](https://opensource.org/licenses/ISC)
repository: will pull in info from the current directory, if present
bugs: will pull in info from the current directory, if present
homepage: will pull in info from the current directory, if present