Sitelet https://github.com/nodejs/node/issues/53944
Skip to content

node: --run requires an argument #53944

Description

@lydell

Affected url(/sitelet?url=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2Fs)

https://nodejs.org/api/cli.html#--run

Description of the problem

The docs for node --run say:

If no "command" is provided, it will list the available scripts.

I thought that meant that if I run node --run, I’ll get a print of all available scripts (similar to how npm run works when not given a script name). But that results in an error:

❯ node --version
v22.5.0
❯ node --run
node: --run requires an argument

It’s still possible to get a listing of all available scripts, by passing a script name that does not exist:

❯ node --run .
ExperimentalWarning: Task runner is an experimental feature and might change at any time

Missing script: "."

Available scripts are:
  test: whatever

I’m not sure what the exact problem is though:

  • Am I just misunderstanding the docs?
  • Are the docs wrong, and the quoted sentence should be removed?
  • Is the implementation wrong, and node --run should in fact print the available scripts?
Thing I found while messing around with this that is probably out of scope in this issue:
❯ node --run ''
Welcome to Node.js v22.5.0.
Type ".help" for more information.
>

Giving the empty string to --run does not try to execute { "scripts": { "": "echo hi" } }. Neither does npm run '' though :)

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    on Jul 19, 2024
  2. added and removed
    docIssues and PRs related to Node.js documentation.
    on Jul 19, 2024
  3. avivkeller commented on Jul 19, 2024

    @avivkeller
    Member

    Reproductions:

    $ node --run ''
    Welcome to Node.js v22.5.0.
    Type ".help" for more information.
    >
    
    $ node --run
    node: --run requires an argument
    
    $ node --run .
    ExperimentalWarning: Task runner is an experimental feature and might change at any time
    
    Missing script: "."
    
    Available scripts are:
    <...>
    
  4. added
    docIssues and PRs related to Node.js documentation.
    on Jul 19, 2024
  5. aduh95 commented on Jul 19, 2024

    @aduh95
    Contributor

    If someone sends a PR to fix the docs, it will probably be accepted.

  6. tniessen commented on Jul 21, 2024

    @tniessen
    Member

    What about the first example from @redyetidev's last comment? What's the expected behavior? Why is there a REPL being started?

  7. avivkeller commented on Jul 21, 2024

    @avivkeller
    Member

    What about the first example from @redyetidev's last comment? What's the expected behavior? Why is there a REPL being started?

    My reproductions were a bit out of order, but at the end of the issue, the author notes:

    Giving the empty string to --run does not try to execute { "scripts": { "": "echo hi" } }. Neither does npm run '' though :)

  8. lydell commented on Jul 21, 2024

    @lydell
    Author

    That doesn’t explain why the repl is started, though? I was surprised when that happened 😄

  9. avivkeller commented on Jul 21, 2024

    @avivkeller
    Member

    That doesn’t explain why the repl is started, though? I was surprised when that happened 😄

    FWIW my assumption is that it treats an empty string as if the flag wasn't there, so it performs the action as if that flag wasn't applied, in this case, trigging the REPL.

  10. tniessen commented on Jul 22, 2024

    @tniessen
    Member

    That's still quite odd and hardly seems desirable... I am wondering if it's intentional. @anonrig

  11. richardlau commented on Jul 22, 2024

    @richardlau
    Member

    Reproductions:

    $ node --run ''
    Welcome to Node.js v22.5.0.
    Type ".help" for more information.
    >
    

    That's odd behaviour. This is valid JSON:

    {
            "name": "nodejs_run_test",
            "scripts": {
                    "hello": "echo hello",
                    "world": "echo world",
                    "": "echo !"
            }
    }

    i.e. it's valid to have an empty string as a JSON key. So I would expect node --run '' to behave the same as if a non-existent script was specified (unless of course a "" script was defined as in the example above).

    FWIW as reference, npm can't run a "" named script:

    $ npm run-script ''
    npm error valid event not provided to runScript
    npm error A complete log of this run can be found in: /home/rlau/.npm/_logs/2024-07-22T12_39_38_822Z-debug-0.log
    $
    

    so Node.js could choose to do the same (but should probably be documented to do so, given that "" is a valid JSON key).

  12. tniessen commented on Jul 22, 2024

    @tniessen
    Member

    Since npm compatibility clearly wasn't a priority, I think it's reasonable for Node.js to implement some reasonable behavior instead.

  13. richardlau commented on Jul 22, 2024

    @richardlau
    Member

    Since npm compatibility clearly wasn't a priority, I think it's reasonable for Node.js to implement some reasonable behavior instead.

    Agreed, I'm just not sure the current behaviour is reasonable 🙂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions