Skip to content

[Bug]: $(NPM_PATH) without having npm in DefaultInfo files leads to errors #3844

@mislavmandaricaxilis

Description

@mislavmandaricaxilis

What happened?

rules_nodejs exposes both NODE_PATH and NPM_PATH but it only adds node to DefaultInfo files.

Using $(NODE_PATH) works well, but when you try to use $(NPM_PATH) it fails with rules_nodejs++node+nodejs_darwin_arm64/bin/npm: No such file or directory.

Should we expose npm alongside node in DefaultInfo provider?

Here's a link to Slack thread where I initially reported this.

Version

Development (host) and target OS/architectures: darwin/arm64

Output of bazel --version: bazel 8.1.1

Version of rules_nodejs, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 6.3.5

Language(s) and/or frameworks involved:

How to reproduce

# From this example: https://github.com/bazel-contrib/rules_nodejs/blob/6b7609179ac1728c6e102d0050117a9b71e55fa5/e2e/smoke/BUILD.bazel#L64C1-L71C2
genrule(
    name = "use_nodejs_toolchain",
    srcs = ["some.js"],
    outs = ["actual1"],
    cmd = "$(NODE_PATH) $(execpath some.js) $@",
    toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
    tools = ["@nodejs_toolchains//:resolved_toolchain"],
)
# this works!

genrule(
    name = "npm_version",
    srcs = [],
    outs = ["actual1"],
    cmd = "$(NPM_PATH) --version",
    toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
    tools = ["@nodejs_toolchains//:resolved_toolchain"],
)
# this fails with /bin/bash: external/rules_nodejs++node+nodejs_darwin_arm64/bin/npm: No such file or directory

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugprioritizedValuable work that we hope to complete soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions