npm package.json scripts not being called

Catfish

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

> [email protected] 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

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:\Users\m089269\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] C:\Program Files\nodejs\node_modules\npm

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

> [email protected] 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! [email protected] 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 [email protected]
npm info using [email protected]
npm ERR! Error: ENOENT, open 'C:\Users\m089269\WebstormProjects\node-mongo-seeds\node_modules\seed\package.json'
...

Why is it looking for a package.json in node_modules\seed? Seed is not even a dependency.

Tim Cooper

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

NPM scripts - config variables and command substitution not working in package.json

From Dev

Externally-located 'npm run' scripts in package.json on Windows?

From Dev

Workaround for NPM Package Missing Minified Scripts

From Dev

BroadcastReceiver not being called when package is removed or updates

From Dev

npm unmet peer dependency on the package being installed

From Dev

Nginx - PHP scripts not being called from reverse proxy

From Dev

JSON parsed data not being called? Swift

From Dev

JSON parsed data not being called? Swift

From Dev

How to get npm package to have working scripts in .bin when installed?

From Dev

Add `jshint` worker into `scripts` for package.json

From Dev

How to install javascript libraries in angularjs not being a npm package/bower component

From Dev

NPM installing Dependencies from package.json

From Dev

How to tune npm package.json?

From Java

Find unused npm packages in package.json

From Java

npm WARN package.json: No repository field

From Java

How to specify the path of `package.json` to npm?

From Java

npm install if package.json was modified

From Dev

npm install error - invalid package.json

From Dev

Change npm default caret(^) in package.json

From Dev

npm package.json and docker (mounting it...)

From Dev

Manage cordova plugins with npm + package.json

From Dev

npm install not reading package.json

From Dev

npm link, not install, package.json dependencies

From Dev

npm install cannot read package.json

From Dev

npm package.json formatted in one line

From Dev

Change the install directory, npm with package.json

From Dev

npm install vs. edit package.json and npm update

From Dev

"npm install [package]" doesn't update package.json

From Dev

npm install package in absolute path (Locally and package.json)

Related Related

  1. 1

    NPM scripts - config variables and command substitution not working in package.json

  2. 2

    Externally-located 'npm run' scripts in package.json on Windows?

  3. 3

    Workaround for NPM Package Missing Minified Scripts

  4. 4

    BroadcastReceiver not being called when package is removed or updates

  5. 5

    npm unmet peer dependency on the package being installed

  6. 6

    Nginx - PHP scripts not being called from reverse proxy

  7. 7

    JSON parsed data not being called? Swift

  8. 8

    JSON parsed data not being called? Swift

  9. 9

    How to get npm package to have working scripts in .bin when installed?

  10. 10

    Add `jshint` worker into `scripts` for package.json

  11. 11

    How to install javascript libraries in angularjs not being a npm package/bower component

  12. 12

    NPM installing Dependencies from package.json

  13. 13

    How to tune npm package.json?

  14. 14

    Find unused npm packages in package.json

  15. 15

    npm WARN package.json: No repository field

  16. 16

    How to specify the path of `package.json` to npm?

  17. 17

    npm install if package.json was modified

  18. 18

    npm install error - invalid package.json

  19. 19

    Change npm default caret(^) in package.json

  20. 20

    npm package.json and docker (mounting it...)

  21. 21

    Manage cordova plugins with npm + package.json

  22. 22

    npm install not reading package.json

  23. 23

    npm link, not install, package.json dependencies

  24. 24

    npm install cannot read package.json

  25. 25

    npm package.json formatted in one line

  26. 26

    Change the install directory, npm with package.json

  27. 27

    npm install vs. edit package.json and npm update

  28. 28

    "npm install [package]" doesn't update package.json

  29. 29

    npm install package in absolute path (Locally and package.json)

HotTag

Archive