Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following scripts section in my projects package.json:

"scripts": {
    "seed": "node bin/seed",
    "test": "echo "Error: no test specified" && exit 1"
  },

If i run $ npm test I get this:

>npm test

> node-mongo-seeds@0.0.1 test C:Usersm089269WebstormProjects
ode-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

If i run $ npm seed, I get this:

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:Usersm089269.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
odejs
ode_modules
pm

Why does it recognize my test script but not my seed script?

EDIT

When I try npm run-script seed I get this error which is expected because I don't pass in a -d param:

$ npm run-script seed

> node-mongo-seeds@0.0.1 seed C:Usersm089269WebstormProjects
ode-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:Usersm089269WebstormProjects
ode-mongo-seeds
ode_modulesseedpackage.json'
...

Why is it looking for a package.json in node_modulesseed? Seed is not even a dependency.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
274 views
Welcome To Ask or Share your Answers For Others

1 Answer

From the 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.)

  • prepare: Run both BEFORE the package is packed and published, on local npm install without any arguments, and when installing git dependencies (See below). This is run AFTER prepublish, but BEFORE 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).

  • postpack: Run AFTER the tarball has been generated and moved to its final destination.

  • publish, postpublish: Run AFTER the package is published.

  • preinstall: Run BEFORE the package is installed

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

  • preuninstall, uninstall: Run BEFORE the package is uninstalled.

  • postuninstall: Run AFTER the package is uninstalled.

  • preupdate: Run BEFORE the package is updated with the update command.

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

  • pretest, test, posttest: Run by the npm test command.

  • prestop, stop, poststop: Run by the npm stop command.

  • prestart, start, poststart: Run by the npm start command.

  • prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...