Skip to content

node --run does not honor script-shell configuration of .npmrc #56456

Description

@michkot

Version

22

Platform

Windows

Subsystem

No response

What steps will reproduce the bug?

This is related to recently added feature #52190

1

Define package with package.json script that is executable in POSIX shell, but it is not executable/portable on cmd.exe.

2

Set script-shell configuration option in .npmrc in your package folder to "bash" (or "sh") to allow cross-platform execution of the script (Scripts will be cross platform as long as the target Windows machine has essential UNIX tools support, e.g. WSL or MSYS/Cygiwn installed).

2

Add a script with the following code or similar: NODE_OPTIONS='--max-old-space-size=8192' ./node_modules/jest/bin/jest

4

Run the script using "npm run", "pnpm run" on Windows system with "bash" available. Will work ok.

Run the script using "node --run". Script will fail with 'NODE_OPTIONS' is not recognized as an internal or external command, operable program or batch file.

How often does it reproduce? Is there a required condition?

N/A

What is the expected behavior? Why is that the expected behavior?

Node --run should work consistently with npm run, pnpm run, etc., in regards to which shell is used to run scripts.

What do you see instead?

See above - Scripts are always executed in default system shell, disregarding .npmrc script-shell option.

Additional information

No response

Activity

  1. deleted a comment from on Jan 3, 2025
  2. deleted a comment from on Jan 3, 2025
  3. anonrig commented on Jan 4, 2025

    @anonrig
    Member

    Node --run is not a replacement of npm or yarn and does not follow npm specific settings. This is intended.

  4. michkot commented on Jan 6, 2025

    @michkot
    Author

    @anonrig I was sort of expecting that answer - let me then just say (as a feedback to a feature being "in adoption") the way this was added, I am afraid node --run is IMO a mistake and will lead increase the existing huge headache of (non-)portability of npm scripts (that we struggle with in devops quite frequently). Thanks for reviewing this promptly tho!

    Picking up some previous feedback I can confirm:
    #46534 (comment) <- noting that package managers actually do much more when running tasks

    #46534 (comment) <- " if this is something that Deno already does, that’s a clear enough signal that Node could do it too", yes, but Deno uses cross-platform shell (similar to yarn and pnpm opt-in feature), not "default system shell" to execute scripts, which makes it much more usable.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions