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

Cannot use nodejs_binary as a tool in genrule if it has npm dependencies #2802

Closed
farcaller opened this issue Jul 1, 2021 · 1 comment
Closed

Comments

@farcaller
Copy link

🐞 bug report

Affected Rule

The issue is caused by the rule: nodejs_binary & genrule

Is this a regression?

N/A

Description

When a nodejs_binary has a npm dependency, such dependency won't be found if the target is called as a tool in a genrule (failing with Error: Cannot find module). bazel run //:helloworld will continue to run as expected.

🔬 Minimal Reproduction

hello.ts:

import { load } from 'js-yaml';
import fs from 'fs';
import { argv } from 'process';

const args = argv.slice(2);

fs.writeFileSync(ags[0], JSON.stringify(load('- hello world')), { encoding: 'utf8' });

BUILD.bazel:

ts_project(
    name = "helloworld_lib",
    srcs = ["hello.ts"],
    tsconfig = "//:tsconfig.json",
    deps = [
        "@npm//@types/node",
        "@npm//@types/js-yaml",
        "@npm//js-yaml",
    ],
)

nodejs_binary(
    name = "helloworld",
    data = [
        ":helloworld_lib",
        // adding the npms here has no effect either
    ],
    entry_point = ":hello.ts",
)

genrule(
    name = "gen_hello",
    outs = ["gen_hello.json"],
    srcs = [],
    cmd = """$(location //:helloworld) $@""",
    tools = [
        "//:helloworld",
    ],
)

🔥 Exception or Error


Error: Cannot find module 'js-yaml'

🌍 Your Environment

Operating System:

  
Linux
  

Output of bazel version:

  
Bazelisk version: v1.9.0
Build label: 4.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jan 21 07:33:24 2021 (1611214404)
Build timestamp: 1611214404
Build timestamp as int: 1611214404
  

Rules_nodejs version:

(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)

  
3.5.1
  

Anything else relevant?

@farcaller
Copy link
Author

Apparently this was already raised in #2600 and the answer is to use npm_package_bin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant