如何取消链接npm命令行工具?

时间:2016-01-27 16:17:19

标签: node.js npm

我使用node编写命令行工具。

这是index.js。

#!/usr/bin/env node
console.log('qiuyuntao');

这是package.json

{
  "name": "qiu",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "bin": {
    "qyt": "index.js"
  }
}

使用命令npm link后,我可以在任何地方使用命令qyt。现在我要取消关联command,我使用npm unlink,它说

npm ERR! gentlyRm containing path /usr/local/lib/node_modules/qiu isn't under npm's control
npm WARN install:qiu@1.0.0 Refusing to delete: /usr/local/bin/qyt not in /usr/local/lib/node_modules/qiu
- qiu@1.0.0 node_modules/qiu

那么,我应该怎么做才能取消链接?

2 个答案:

答案 0 :(得分:0)

在不知道你正在使用的npm版本的情况下,如果这是一个被解决的错误,我怀疑你的全局前缀可能是错误配置的。

无论如何,最简单的解决方案是手动删除符号链接/usr/local/bin/qyt/usr/local/lib/node_modules/qiu。如果您使用的是最新版本的npm,请查看提交问题,否则请更新(npm i -g npm)。

答案 1 :(得分:0)

更新npm 3.9.5> 4.0.5为我解决了同样的问题

更新前:

$ npm unlink
npm WARN install:@coolman/my-module@1.0.0 Refusing to delete /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod: ../lib/node_modules/my-module/index-cli.js symlink target is not controlled by npm /Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/@coolman/my-module
- @coolman/my-module@1.0.0 node_modules/@coolman/my-module

$ npm --version
3.9.5

更新后:

$ sudo npm install npm@latest -g

$ npm --version
4.0.5

$ npm unlink
- @coolman/my-module@1.0.0 node_modules/@coolman/my-module

要重复npm link,我需要手动删除bin:

$ npm link
npm WARN @my-company/my-module@1.0.0 No repository field.
npm ERR! Darwin 16.1.0
npm ERR! argv "/Users/coolman/.nvm/versions/node/v6.2.0/bin/node" "/Users/coolman/.nvm/versions/node/v6.2.0/bin/npm" "link"
npm ERR! node v6.2.0
npm ERR! npm  v4.0.5
npm ERR! path /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
npm ERR! code EEXIST

npm ERR! Refusing to delete /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod: ../lib/node_modules/my-module/index-cli.js symlink target is not controlled by npm /Users/coolman/my-company/tools/my-module
npm ERR! File exists: /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
npm ERR! Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/coolman/my-company/tools/my-module/npm-debug.log


$ rm /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod

$ npm link
npm WARN @coolman/my-module@1.0.0 No repository field.
/Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod -> /Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/@coolman/my-module/index-cli.js
/Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/@coolman/my-module -> /Users/coolman/perkbox/tools/run-with-pb-session