But when the arguments contain option(s) (e.g. -p), -- is necessary otherwise npm will parse them and treat them as npm's option.npm run test -- 8080 -p使用位置参数参数只是附加到要运行的脚本中.你的 $1 $2 不会被解析.npm实际运行的命令是:Use positional parametersThe arguments are just appended to the script to be run. Your $1 $2 won't be resolved. The command that npm actually runs is:node mytest.js $1 $2 | node_modules/tap-difflet/bin/tap-difflet "8080" "production"为了使位置变量在 npm 脚本中起作用,请将命令包装在 shell 函数中:In order to make position variable works in npm script, wrap the command inside a shell function:"scripts": { "test": "run(){ node mytest.js $1 $2 | node_modules/tap-difflet/bin/tap-difflet; }; run"}或者使用工具 scripty 并将您的脚本放在一个单独的文件中.Or use the tool scripty and put your script in an individual file.package.json:"scripts": { "test": "scripty"}脚本/测试:#!/usr/bin/env shnode mytest.js $1 $2 | node_modules/tap-difflet/bin/tap-difflet 这篇关于将参数传递给 package.json 中的 npm 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 10:08