我的项目包中有以下脚本部分.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\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,我会得到这样的结果:

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

为什么它能识别我的test脚本而不能识别我的seed脚本?

EDIT

当我try npm run-script seed时,我会出现这个错误,这是意料之中的,因为我没有传递-d参数:

$ npm run-script seed

> node-mongo-seeds@0.0.1 seed C:\Users\m089269\WebstormProjects\node-mongo-seeds
> node bin/seed

Populate mongo from a set of .json files.
 Usage: $ node seed

Options:
  -d  The path to your mongo db  [required]

Missing required arguments: d

npm ERR! node-mongo-seeds@0.0.1 seed: `node bin/seed`
npm ERR! Exit status 1
...

When I try npm run-script seed -d "localhost/ease" I get this error.

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_module\Seed中查找Package.json?种子甚至不是依赖项.

推荐答案

documentation人中:

npm supports the "scripts" member of the package.json script, for the following scripts:

  • prepublish: Run BEFORE the package is published. (Also run on local npm install without any arguments.)

  • 准备:在打包和发布包之前,在本地npm install上不带任何参数,以及在安装git依赖项(见下文)时运行.这是在prepublish之后运行的,但是在prepublishOnly之前运行.

  • prepublishOnly: Run BEFORE the package is prepared and packed, ONLY on npm publish.

  • prepack: run BEFORE a tarball is packed (on npm pack, npm publish, and when installing git dependencies).

  • 后置:在tarball生成并移动到最终目的地后运行

  • 发布,后发布:在发布包后运行.

  • 预安装:在安装软件包之前运行

  • install, postinstall: Run AFTER the package is installed.

  • 预卸载,卸载:在卸载程序包之前运行.

  • postuninstall: Run AFTER the package is uninstalled.

  • preupdate:在使用update命令更新包之前运行.

  • update, postupdate: Run AFTER the package is updated with the update command.

  • pretest、test、posttest:由npm test命令运行.

  • prestop、stop、poststop:通过npm stop命令运行.

  • 启动前、启动后、启动后:通过npm start命令运行.

  • prerestart、restart、postretart:通过npm restart命令运行.注意:如果没有提供restart脚本,npm restart将运行停止和启动脚本

Additionally, arbitrary scripts can be run by doing npm run-script <stage> <pkg>.

You can see the reason why your npm test script works is because npm test is a built-in command. You must use npm run-script if you want to execute a script that is not executed by a built-in npm command.

Json相关问答推荐

Elasticsearch Go客户端错误:无效的SON格式:在中间件中索引文档时出错

使用Shell深入挖掘到最低的SON元素

Golang JSON Date Tim.Date()测试请求

有没有办法让serde_json正确/不正确地处理NaN、inf和-inf(IEEE 754特殊标准)?

NoneType 对象的 Python 类型错误

交换键和数组值,将旧键转换为新数组值,使用 jq

报告重复的对象键

在 json 对象中存储多个键:值对

如何使用jq按键 Select 并获取整个json输出来更改json中的多个值

如何使用jolt将嵌套数据变成线性数据

Golang 解组行为:字段过多?

如何在 Flutter 中遍历嵌套的动态 JSON 文件

Rails 控制器无需编码即可渲染 json

为什么JsonConvert反序列化对象以int但不长失败

如何使用 gson 将数据保存在 json 文件中?

在 JavaScript 中从 Json 数据中删除反斜杠

JSON对象中的JavaScript递归搜索

使用 ajax 将 JSON 发送到 PHP

JSON 使用 simplejson 序列化 Django 模型

as_json 没有在关联上调用 as_json