Insatll node package on Virtualbox Share Folder

剛開始學 js, 試著想在 vm 的共享資料夾安裝套件, 卻出現以下錯誤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
npm ERR! code EPERM
npm ERR! syscall symlink
npm ERR! path ../n/bin/n
npm ERR! dest /*/node_modules/.bin/n
npm ERR! errno -1
npm ERR! Error: EPERM: operation not permitted, symlink '../n/bin/n' -> '/*/nodejs/node_modules/.bin/n'
npm ERR! [Error: EPERM: operation not permitted, symlink '../n/bin/n' -> '/*/nodejs/node_modules/.bin/n'] {
npm ERR! errno: -1,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'symlink',
npm ERR! path: '../n/bin/n',
npm ERR! dest: '/*/nodejs/node_modules/.bin/n'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

發現很早就有人碰到這個問題: npm does not work with Virtualbox shared folders. #992

似乎可以用 npm install –no-bin-links 的方式來解決

但我覺得很麻煩, 想說乾脆試試 yarn, 照著官網說明步驟安裝, 結果測試的時候改出現 Cannot find module 錯誤, 想說用 yarn info 明明就看的到那套件, 怎麼會呼叫不到, 後來看到這發文才知道似乎是 yarn 的 Plug’n’Play 特性, 不能使用 node hello.js, 而是要使用 yarn node hello.js 才能正常抓到安裝的套件, 儘管不太懂其中原理, 但能跑比較重要, 就先這樣吧.