[英]How to pass command-line variable in package.json script, in NPM?
[英]How to unlink a npm command-line tool?
我使用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
那么,我應該怎么做才能取消鏈接?
在不知道您使用的是npm版本的情況下,如果這是一個已解決的錯誤,我懷疑您的全局前綴可能配置錯誤。
無論如何,最簡單的解決方案是手動刪除符號鏈接/usr/local/bin/qyt
和/usr/local/lib/node_modules/qiu
。 如果您使用的是最新版本的npm,請考慮提出問題,否則進行更新( npm i -g npm
)。
更新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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.