1. 程式人生 > >npm ERR! File exists: /XXX/xxx npm ERR! Move it away, and try again.

npm ERR! File exists: /XXX/xxx npm ERR! Move it away, and try again.

今天抽空將我的靜態服務 ks-server 之前留下的 bug(在node低版本情況下報錯)維護了一下。

當我重新 npm link 時,如下錯誤:

npm WARN [email protected] No repository field.
npm ERR! Darwin 17.5.0
npm ERR! argv "/Users/zhuqiang/.nvm/versions/node/v6.4.0/bin/node" "/Users/zhuqiang/.nvm/versions/node/v6.4.0/bin/npm" "link"
npm ERR! node v6.4.0
npm ERR! npm  v3.10.3
npm ERR! path /Users/zhuqiang/.nvm/versions/node/v6.4.0/bin/ks-server
npm ERR! code EEXIST

npm ERR! Refusing to delete /Users/zhuqiang/.nvm/versions/node/v6.4.0/bin/ks-server: ../lib/node_modules/ks-server/bin/www.js symlink target is not controlled by npm /Users/zhuqiang/github/ks-server
npm ERR! File exists: /Users/zhuqiang/.nvm/versions/node/v6.4.0/bin/ks-server
npm ERR! Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/zhuqiang/github/ks-server/npm-debug.log

我注意到,bug 日誌中有:

npm ERR! File exists: /Users/zhuqiang/.nvm/versions/node/v6.4.0/bin/ks-server
npm ERR! Move it away, and try again.

突然意識到, 闊能是之前已經生成了一個 ks-server 這樣一個 link,當我修改 package.json 中的 bin 時,使其與當前的 ks-server 命令對不上。而報錯,且日誌中的 Move it away, and try again 也有次意思。

於是,(解決方法):

cd /Users/zhuqiang/.nvm/versions/node/v6.4.0/bin
rm -rf ks-server

然後回到專案目錄,重新 npm link 就 bingo 了。