Cli: NPM 7 fails with an empty script.

Created on 13 Nov 2020  路  9Comments  路  Source: npm/cli

Current Behavior:

NPM 7 fails with an empty script.

Expected Behavior:

Not to fail.

Steps To Reproduce:

package.json:

{
  "scripts": {
    "empty": ""
  }
}

Command

npm run empty

Result:

npm ERR! missing script: empty
npm ERR!
npm ERR! Did you mean this?
npm ERR!     empty

Environment:

  • OS: MacOS 10.15.7
  • Node: 14.15.0
  • npm: 7.0.10
Bug Release 7.x

All 9 comments

What does npm 6 do here?

What does npm 6 do here?

Doesn鈥檛 fails.

Workaround is to add a space:

{
  "scripts": {
    "empty": " "
  }
}

this is technically a bug, but i'm curious about the use case for having empty scripts and expecting to be able to run them.. is the idea to make sure that the command always works?

if so: npm run --if-present empty will probably do what you want

Seems like any script that trims to the empty string should be treated as an error case, distinct from missing scripts - I鈥檓 curious about the use case for an empty script.

my guess was a build system of some sort that runs npm run empty for every project it builds, which is why i suggested the --if-present flag since that would run the script if it exists and do nothing at all if it doesn't

Seems like any script that trims to the empty string should be treated as an error case, distinct from missing scripts - I鈥檓 curious about the use case for an empty script.

Not against it but the error message should be fixed.
At jhipster we generate a bunch of scripts, with pre scripts.
In some cases we generate some empty scripts, because that script does not apply.
To keep scripts 'api' stable with pre scripts, the both are generated blank. --if-present is a little more error prone for our use case. If the generator failed to generate the script, CI will still pass.

fair enough :+1:

pull request to fix it is up and will hopefully land in the next release

Thanks.

Was this page helpful?
0 / 5 - 0 ratings