npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

`preinstall` `npx` script failed to run with fresh `npm i --only=dev`

preinstall npx script failed to run with fresh npm i --only=dev

What I Wanted to Do

run npx setup command in preinstall script,
then install packages from devDependencies only,
with command npm install --only=dev

What Happened Instead

npx will log npx: installed 0 in 0.952s,
and not install the package to cache,
so the preinstall will fail with command not found

Reproduction Steps

in a fresh directory (with no node_modules, an no global marked installed)

with package.json:

  "scripts": {
    "preinstall": "npx marked -s test"
  "devDependencies": {
    "marked": "*"

and run npm i --only=dev

will output:

$ npm i --only=dev

> @ preinstall /home/ubuntu/TEST
> npx marked

npx: installed 0 in 0.952s
command not found: marked
npm ERR! errno 1
npm ERR! @ preinstall: `npx marked`
npm ERR! Exit status 1


whether putting marked into devDependencies will not affect the error

with marked existing in node_modules or globally installed will pass

the npm-debug.log file: 2018-12-27T02_51_42_454Z-debug.log (2.0 KB)

Platform Info

$ npm --versions
{ npm: '6.5.0',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.14.2',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '',
  zlib: '1.2.11' }

$ node -p process.platform

also tested on windows