npm publish 发布示例

# 初始化 package.json
C:UsersLellansinDocumentsGitHubnode-net-scan>npm init

# 验证你在 npmjs.org 上的账号
C:UsersLellansinDocumentsGitHubnode-net-scan>npm adduser

# 发布
C:UsersLellansinDocumentsGitHubnode-net-scan>npm publish .
npm http PUT http://registry.npmjs.org/net-scan
npm http 400 http://registry.npmjs.org/net-scan
npm http PUT http://registry.npmjs.org/net-scan
npm http 201 http://registry.npmjs.org/net-scan
npm http GET http://registry.npmjs.org/net-scan
npm http 200 http://registry.npmjs.org/net-scan
npm http PUT http://registry.npmjs.org/net-scan/-/net-scan-0.0.0.tgz/-rev/1-96a1
2fd6f9e8e5359489a9f59d114f90
npm http 201 http://registry.npmjs.org/net-scan/-/net-scan-0.0.0.tgz/-rev/1-96a1
2fd6f9e8e5359489a9f59d114f90
npm http PUT http://registry.npmjs.org/net-scan/0.0.0/-tag/latest
npm http 201 http://registry.npmjs.org/net-scan/0.0.0/-tag/latest
+ net-scan@0.0.0

如果你以后修改了代码,然后想要同步到 npm 上的话请修改 package.json 中的 version 然后再次 publish

使用 cnpm 的注意报错:

no_perms Private mode enable, only admin can publish this module

设置回原本的就可以了

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

npm 安装出现 UNMET DEPENDENCY 的解决方案

npm install express -g
...
npm list -g
D:UsersLsAppDataRoamingnpm
└─┬ express@3.4.8
  ├── buffer-crc32@0.2.1
  ├─┬ commander@1.3.2
  │ └── keypress@0.1.0
  ├─┬ connect@2.12.0
  │ ├── UNMET DEPENDENCY batch 0.5.0
  │ ├── UNMET DEPENDENCY bytes 0.2.1
  │ ├── UNMET DEPENDENCY multiparty 2.2.0
  │ ├── UNMET DEPENDENCY negotiator 0.3.0
  │ ├── UNMET DEPENDENCY pause 0.0.1
  │ ├── UNMET DEPENDENCY qs 0.6.6
  │ ├── UNMET DEPENDENCY raw-body 1.1.2
  │ └── UNMET DEPENDENCY uid2 0.0.3
  ├── cookie@0.1.0
  ├── cookie-signature@1.0.1
  ├── debug@0.7.4
  ├── fresh@0.2.0
  ├── merge-descriptors@0.0.1
  ├── methods@0.1.0
  ├── mkdirp@0.3.5
  ├── range-parser@0.0.4
  └─┬ send@0.1.4
    └── mime@1.2.11

npm ERR! missing: batch@0.5.0, required by connect@2.12.0
npm ERR! missing: bytes@0.2.1, required by connect@2.12.0
npm ERR! missing: pause@0.0.1, required by connect@2.12.0
...
npm ERR! not ok code 0

今天安装一些模块的时候发现 npm install 到了一个点之后就卡住了一样等了半天一直不动,接着中断看了下出现安装出现了 UNMET DEPENDENCY 的 模块,这个时候如果重新 install 一便的话,又会重头开始,如果又碰到卡壳就很烦。

查了一下发现是跟旧版 npm 有关的问题: https://github.com/isaacs/npm/issues/1341#issuecomment-20634338

方案一

rm -rf node_modules/    # 删除已安装的模块
npm cache clean         # 清除 npm 内部缓存
npm install             # 重新安装

方案二

rm -rf node_modules/    # 删除已安装的模块
sudo npm update -g npm  # 更新 npm
npm install             # 重新安装

方案三

npm list 命令查看之后跑到缺失模块的目录下, 手动修复部分出错的模块:

$ npm list -g
D:UsersLsAppDataRoamingnpm
└─┬ express@3.4.8
  ├── buffer-crc32@0.2.1
  ├─┬ commander@1.3.2
  │ └── keypress@0.1.0
  ├─┬ connect@2.12.0
  │ ├── UNMET DEPENDENCY batch 0.5.0
  │ ├── UNMET DEPENDENCY bytes 0.2.1
  │ ├── UNMET DEPENDENCY multiparty 2.2.0
  │ ├── UNMET DEPENDENCY negotiator 0.3.0
  │ ├── UNMET DEPENDENCY pause 0.0.1
  │ ├── UNMET DEPENDENCY qs 0.6.6
  │ ├── UNMET DEPENDENCY raw-body 1.1.2
  │ └── uid2@0.0.3
  ├── cookie@0.1.0
  ├── cookie-signature@1.0.1
  ├── debug@0.7.4
  ├── fresh@0.2.0
  ├── merge-descriptors@0.0.1
  ├── methods@0.1.0
  ├── mkdirp@0.3.5
  ├── range-parser@0.0.4
  └─┬ send@0.1.4
    └── mime@1.2.11

npm ERR! missing: batch@0.5.0, required by connect@2.12.0
npm ERR! missing: qs@0.6.6, required by connect@2.12.0
npm ERR! missing: bytes@0.2.1, required by connect@2.12.0
npm ERR! missing: pause@0.0.1, required by connect@2.12.0
npm ERR! missing: raw-body@1.1.2, required by connect@2.12.0
npm ERR! missing: negotiator@0.3.0, required by connect@2.12.0
npm ERR! missing: multiparty@2.2.0, required by connect@2.12.0
npm ERR! not ok code 0

可以 cd 到具体出问题的模块目录下手动 npm install 重新安装也可以解决.