0

I am trying to execute a locally saved npm package, but it is not found.

npm run jsdoc

Outputs:

npm ERR! Linux 4.15.0-24-generic
npm ERR! argv "/usr/bin/node" "/usr/local/bin/npm" "run" "jsdoc"
npm ERR! node v8.10.0
npm ERR! npm  v3.10.10

npm ERR! missing script: jsdoc
...

But I know the script is located in my node_modules/.bin, and can execute it directly:

jsdoc -> ../jsdoc/jsdoc.js*

And running it works as a pre-configured command on my package.json

  "scripts": {                                                                                                                                                                                                                                                                                                                                                                                  
    "doc": "jsdoc"                                                                                                                                                                                          
  },

Is there a special environment configuration (npmrc or something similar) to make npm run look at both package.json scripts and in node_modules/.bin?

What am I missing?

null
  • 404
  • 6
  • 12
  • 1
    Why do you need to run it via `npm run` instead of just running `jsdoc`? – Charles Stover Jul 06 '18 at 16:23
  • I can't install any global packages (-g), and also wouldn't like to have to change package.json for this. I was looking in the aswers in https://stackoverflow.com/questions/9679932/how-to-use-package-installed-locally-in-node-modules and I think I figured it out. I got confused by the npm-run answer (which is a package). There is actually no way to run the command locally without messing with package.json, setting the PATH, or going directly to node_modules/.bin. Thanks Charles! – null Jul 06 '18 at 16:48

1 Answers1

0

The command npm run is an alias for npm run-script. As seen in the docs:

SYNOPSIS
       npm run-script <command> [-- <args>...]

       alias: npm run

It will only add node_modules/.bin to context inside scripts edited in package.json.

The npm-run answer can be misleading as one can think npm commands could be referenced as git sub-commands would (git-init, git-clone etc), which in this particular case is a separate package, not related to npm run-script.

null
  • 404
  • 6
  • 12