节点命令行工具未在 vagrant 上编译

node command line tools are not compiled on vagrant

我在 Windows 10 上使用 Vagrant。 使用 npm install(或 npm install --no-bin-links,因为我在 Windows 上的 Vagrant 安装了所有依赖项后,./node_modules/.bin 是空的。我希望在那里找到一些命令行工具。

在我的例子中,缺少 svg2png-many

我也尝试用 npm rebuild svg2png-many 重建,但这并没有创建丢失的文件。

注意:我没有收到任何错误 运行 npm install,只是文件不存在:

./svg2png.sh: line 8: ./node_modules/.bin/svg2png-many: No such file or directory

这在那个文件里

for t in "${themes[@]}"
do
  echo "dist/img/${t}/"
  ./node_modules/.bin/svg2png-many -i "dist/img/${t}/" "dist/img/${t}/"
done

接下来我应该尝试什么?

如果您指定 --no-bin-links,二进制文件将不会在 ./node_modules/.bin 中可用,因为它们是模块二进制文件的符号链接。您可以在 npm documentation:

中看到

The --no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.

如果您 运行 npm install 您应该将 package.json 文件中的所有模块下载到 node_modules 文件夹中。这是一个输出示例(安装后没有 --no-bin-links 标志):

$ ls -l node_modules/.bin
total 0
lrwxrwxrwx 1 ils ils 36 may 17 17:01 conventional-changelog -> ../conventional-changelog-cli/cli.js
lrwxrwxrwx 1 ils ils 39 may 17 17:01 conventional-changelog-writer -> ../conventional-changelog-writer/cli.js
lrwxrwxrwx 1 ils ils 37 may 17 17:01 conventional-commits-parser -> ../conventional-commits-parser/cli.js
lrwxrwxrwx 1 ils ils 39 may 17 17:01 conventional-recommended-bump -> ../conventional-recommended-bump/cli.js
lrwxrwxrwx 1 ils ils 34 may 17 17:01 cross-env -> ../cross-env/dist/bin/cross-env.js
lrwxrwxrwx 1 ils ils 24 may 17 17:01 dateformat -> ../dateformat/bin/cli.js
lrwxrwxrwx 1 ils ils 22 may 17 17:01 get-pkg-repo -> ../get-pkg-repo/cli.js
lrwxrwxrwx 1 ils ils 25 may 17 17:01 git-raw-commits -> ../git-raw-commits/cli.js
lrwxrwxrwx 1 ils ils 25 may 17 17:01 git-semver-tags -> ../git-semver-tags/cli.js
lrwxrwxrwx 1 ils ils 28 may 17 17:01 handlebars -> ../handlebars/bin/handlebars
lrwxrwxrwx 1 ils ils 22 may 17 17:01 JSONStream -> ../JSONStream/index.js
lrwxrwxrwx 1 ils ils 21 may 17 17:01 lerna -> ../lerna/bin/lerna.js
lrwxrwxrwx 1 ils ils 20 may 17 17:00 mkdirp -> ../mkdirp/bin/cmd.js
lrwxrwxrwx 1 ils ils 39 may 17 17:01 npm-run-all -> ../npm-run-all/bin/npm-run-all/index.js
lrwxrwxrwx 1 ils ils 16 may 17 17:01 rimraf -> ../rimraf/bin.js
lrwxrwxrwx 1 ils ils 33 may 17 17:01 run-p -> ../npm-run-all/bin/run-p/index.js
lrwxrwxrwx 1 ils ils 33 may 17 17:01 run-s -> ../npm-run-all/bin/run-s/index.js
lrwxrwxrwx 1 ils ils 20 may 17 17:00 semver -> ../semver/bin/semver
lrwxrwxrwx 1 ils ils 51 may 17 17:01 sl-log-transformer -> ../strong-log-transformer/bin/sl-log-transformer.js
lrwxrwxrwx 1 ils ils 22 may 17 17:00 strip-indent -> ../strip-indent/cli.js
lrwxrwxrwx 1 ils ils 25 may 17 17:01 uglifyjs -> ../uglify-js/bin/uglifyjs
lrwxrwxrwx 1 ils ils 18 may 17 17:01 which -> ../which/bin/which

如果需要安装缺少的模块,可以在运行ning npm install之前删除所有下载的依赖,或者直接通过运行ning npm install svg2png-many安装依赖.

我 运行 命令并在 ./node_modules/svg2png-many 中下载 svg2png-many,二进制文件存在于 ./node_modules/svg2png-many/bin/index.js 中。您可以直接 运行 该文件(而不是尝试使用未在 ./node_modules/.bin 中创建的符号链接)

重要说明:在 Windows 上使用 Vagrant 时,为了 npm install 工作,您必须

  • 运行 以管理员身份 vagrant up 启动的控制台
  • 或使用选项 --no-bin-links

第一个显然是此处所需的解决方案。