2014-05-08 21 views
18

ho la sezione seguente script nel mio progetti package.json:script package.json NPM non essere chiamato

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

Se corro $ npm test ottengo questo:

>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 

Se corro $ npm seed , Ho capito:

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 

Perché riconosce il mioScriptma non lo script seed?

EDIT

Quando provo npm run-script seed ottengo questo errore che dovrebbe perché non passare un -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 
... 

Quando provo npm run-script seed -d "localhost/ease" ottengo questo errore.

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' 
... 

Perché è in cerca di un pacchetto. Json in node_modules \ seed? Il seme non è nemmeno una dipendenza.

risposta

44

Dal documentation:

NPM supporta il membro "script" dello script package.json, per i seguenti script:

  • prepublish: Eseguire prima che il pacchetto viene pubblicato. (Esegui anche su locale npm install senza argomenti.)
  • pubblica, postpublish: Esegui DOPO che il pacchetto è stato pubblicato.
  • preinstall: Esegui PRIMA che il pacchetto sia installato
  • installa, postinstall: avvia DOPO il pacchetto è installato.
  • preuninstall, uninstall: Esegui PRIMA che il pacchetto sia disinstallato.
  • postuninstall: Esegui dopo che il pacchetto è stato disinstallato.
  • preupdate: Esegui PRIMA che il pacchetto sia aggiornato con il comando di aggiornamento.
  • aggiornamento, postupdate: avvia DOPO il pacchetto viene aggiornato con il comando di aggiornamento.
  • pretest, test, post test: eseguito dal comando npm test.
  • prestop, stop, poststop: eseguito dal comando npm stop.
  • prestart, start, poststart: eseguito dal comando npm start.
  • prerestart, restart, postrestart: eseguito dal comando npm restart. Nota: npm restart eseguirà la fermata e avvia gli script se non viene fornito lo script restart.

Inoltre, è possibile eseguire script arbitrari eseguendo npm run-script <stage> <pkg>.

Si può vedere il motivo per cui lo script npm test funziona è perché npm test è un comando integrato. È necessario utilizzare npm run-script se si desidera eseguire uno script che non viene eseguito da un comando npm incorporato.

+0

Questo è molto utile informazioni. Si prega di vedere la mia modifica alla mia domanda anche se qualcosa non va ancora bene. – Catfish

+0

Sembra che npm run-script attualmente non supporti il ​​passaggio negli argomenti. Quindi per ora ho semplicemente codificato il valore -d nella sezione script "script": {"seed": "node bin/seed -d localhost/ease" ... " – Catfish

+0

Supponendo che npm passi l'ambiente locale a script, si potrebbe avere lo script del nodo letto in variabili d'ambiente per l'impostazione dei parametri. – mscdex

7

Gli script personalizzati dichiarati nel pacchetto.json possono essere eseguiti con il modulo npm run <your-script> nella shell.

Prova npm run seed o npm run test

+0

Benvenuti in SO! La tua risposta sembra un commento piuttosto che una risposta. Una volta che hai [reputazione] sufficiente (http://stackoverflow.com/help/whats-reputation) sarai in grado di [commentare] (http://stackoverflow.com/help/privileges/comment) su qualsiasi post. Controlla anche questo [cosa posso fare invece] (https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). Se intendevi rispondere, leggi questo [how-to-answer] (http://stackoverflow.com/help/how-to-answer) per seguire le linee guida SO. – thewaywewere

Problemi correlati