Javascript 未调用npm package.json脚本
我的projects package.json中有以下脚本部分:Javascript 未调用npm package.json脚本,javascript,json,node.js,npm,Javascript,Json,Node.js,Npm,我的projects package.json中有以下脚本部分: "scripts": { "seed": "node bin/seed", "test": "echo \"Error: no test specified\" && exit 1" }, 如果我运行$npm test,我会得到以下结果: >npm test > node-mongo-seeds@0.0.1 test C:\Users\m089269\WebstormProjec
"scripts": {
"seed": "node bin/seed",
"test": "echo \"Error: no test specified\" && exit 1"
},
如果我运行$npm test
,我会得到以下结果:
>npm test
> node-mongo-seeds@0.0.1 test C:\Users\m089269\WebstormProjects\node-mongo-seeds
> echo "Error: no test specified" && exit 1
"Error: no test specified"
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
npm seed
Usage: npm <command>
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, repo, restart, rm,
root, run-script, s, se, search, set, show, shrinkwrap,
star, stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, v,
version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\m089269\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@1.4.3 C:\Program Files\nodejs\node_modules\npm
如果我运行$npm seed
,我会得到以下结果:
>npm test
> node-mongo-seeds@0.0.1 test C:\Users\m089269\WebstormProjects\node-mongo-seeds
> echo "Error: no test specified" && exit 1
"Error: no test specified"
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
npm seed
Usage: npm <command>
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, repo, restart, rm,
root, run-script, s, se, search, set, show, shrinkwrap,
star, stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, v,
version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\m089269\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@1.4.3 C:\Program Files\nodejs\node_modules\npm
当我尝试npm运行脚本seed-d“localhost/ease”
时,我得到了这个错误
npm run-script seed -d localhost/ease-dev
npm info it worked if it ends with ok
npm info using npm@1.4.3
npm info using node@v0.10.26
npm ERR! Error: ENOENT, open 'C:\Users\m089269\WebstormProjects\node-mongo-seeds\node_modules\seed\package.json'
...
为什么要在node_modules\seed中查找package.json?种子甚至不是依赖项。来自:
对于以下脚本,npm支持package.json脚本的“scripts”成员:
- 预发布:在发布包之前运行。(也在本地
npm安装上运行,不带任何参数。)
- 准备:在打包和发布包之前、在本地
上(不带任何参数)以及在安装git依赖项时(请参见下文)运行。这在npm install
之后运行,但在prepublish
之前运行prepublishOnly
- prepublishOnly:仅在
上,在准备和打包包之前运行npm publish
- 预打包:在打包tarball之前运行(在
,npm-pack
,以及安装git依赖项时)npm-publish
- 后置:生成tarball并将其移动到最终目的地后运行
- 发布,后发布:在发布包后运行
- 预安装:在安装包之前运行
- 安装,后安装:安装软件包后运行
- 预卸载,卸载:在卸载包之前运行
- postninstall:卸载包后运行
- preupdate:在使用update命令更新包之前运行
- update,postpdate:使用update命令更新包后运行
- 预测试、测试、后测试:通过
命令运行npm test
- 预停止、停止、后停止:通过
命令运行npm-stop
- 启动前、启动后、启动后:通过
命令运行npm start
- 预重启、重启、后重启:通过
命令运行。注意:npm restart
将在未提供npm restart
脚本的情况下运行停止和启动脚本restart
npm run script
来运行任意脚本
您可以看到
npm-test
脚本工作的原因是npm-test
是一个内置命令。如果要执行不是由内置npm命令执行的脚本,则必须使用npm run script
。包中声明的自定义脚本。json可以使用shell中的npm run
表单运行
尝试
npm run seed
或npm run test
执行package.json中的自定义脚本,方法如下
npm运行脚本种子
或
npm运行脚本npm运行
“scripts”:{“seed”:“node bin/seed-d localhost/ease”…
假设npm将本地环境传递给脚本,您可以在环境变量中读取节点脚本以设置参数。请注意,npm run script
的别名是npm run
请注意,他们在最新版本中做了一些更改。值得注意的是,他们删除了update/shrinkwrap脚本,并添加了一个版本s欢迎来到SO!您的回复看起来像是一个评论,而不是一个答案。一旦您有足够的答案,您将能够在任何帖子上发表。同时检查此项。如果您打算回答,请阅读此项以遵循SO指南。