Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM 7 fails with an empty script. #2171

Closed
mshima opened this issue Nov 13, 2020 · 10 comments
Closed

NPM 7 fails with an empty script. #2171

mshima opened this issue Nov 13, 2020 · 10 comments
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@mshima
Copy link

mshima commented Nov 13, 2020

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
@mshima mshima added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Nov 13, 2020
@mshima mshima changed the title [BUG] <title> NPM 7 fails with an empty script. Nov 13, 2020
@ljharb
Copy link
Contributor

ljharb commented Nov 13, 2020

What does npm 6 do here?

@mshima
Copy link
Author

mshima commented Nov 13, 2020

What does npm 6 do here?

Doesn’t fails.

@mshima
Copy link
Author

mshima commented Nov 13, 2020

Workaround is to add a space:

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

@nlf
Copy link
Contributor

nlf commented Nov 13, 2020

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

@nlf nlf self-assigned this Nov 13, 2020
@nlf nlf removed the Needs Triage needs review for next steps label Nov 13, 2020
@ljharb
Copy link
Contributor

ljharb commented Nov 13, 2020

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

@nlf
Copy link
Contributor

nlf commented Nov 13, 2020

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

@mshima
Copy link
Author

mshima commented Nov 13, 2020

Seems like any script that trims to the empty string should be treated as an error case, distinct from missing scripts - I’m 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.

@nlf nlf mentioned this issue Nov 13, 2020
@nlf
Copy link
Contributor

nlf commented Nov 13, 2020

fair enough 👍

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

@mshima
Copy link
Author

mshima commented Nov 13, 2020

Thanks.

@nlf
Copy link
Contributor

nlf commented Nov 23, 2020

this was resolved in 7.0.12

@nlf nlf closed this as completed Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants