我在 Linux Vagrant 机器上尝试 npm install 时遇到了 ENOENT 错误。配置脚本中的代码如下:
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
cd <directory with package.json> && npm install
错误输出为:
npm ERR! Linux 4.15.0-58-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--no-bin-links"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code EMISSINGARG
npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror <http://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR!
我对 Vagrant 还很陌生,但我觉得这像是 npm 中出现了问题,而不是 package.json 出了问题?
答案1
据说,解决方案在这里 https://www.speich.net/articles/en/2018/12/24/virtualbox-6-how-to-enable-symlinks-in-a-linux-guest-os/ 应该可以解决这个问题。但我发现它不起作用。我确实启用了它。
我所做的是:
node_modules
彻底移除- 在客户机中创建一个目录
~/node_modules
cd my-project-dir; ln -s ~/node_modules
。npm install
到那时,一切运行正常。不管“setextradata”应该如何工作,似乎在主机同步目录中创建符号链接仍然存在问题。