aspect-build / aspect-build/rules_js

Unable to `bazel run` a `js_binary()` on Windows

Open
#481 0 comments 0 reactions 0 assignees View on GitHub
bug help wanted windows
Dominant language
Starlark
Stars
378
Forks
183
Avg merge
1d 9h
Merged PRs (30d)
32

Description

Trying to `bazel run` a binary created with `js_binary()` (using 86b7aaa) on Windows fails with the following error:

```
FATAL: aspect_rules_js[js_binary]: BAZEL_BINDIR must be set in environment to the makevar $(BINDIR) in js_binary build actions (which run in the execroot) so that build actions can change directories to always run out of the root of the Bazel output tree. See https://docs.bazel.build/versions/main/be/make-variables.html#predefined_variables. This is automatically set by 'js_run_binary' (https://github.com/aspect-build/rules_js/blob/main/docs/js_run_binary.md) which is the recommended rule to use for using a js_binary as the tool of a build action. If this is not a build action you can set the BAZEL_BINDIR to '.' instead to supress this error. For more context on this design decision, please read the aspect_rules_js README https://github.com/aspect-build/rules_js/tree/dbb5af0d2a9a2bb50e4cf4a96dbc582b27567155#running-nodejs-programs.
```

This `bazel run` is successfull on Linux/Mac. A `js_run_binary()` works.

I would guess the error is due to https://github.com/aspect-build/rules_js/blob/86b7aaa3d4bcafaf30bbaf04fba2b7c1d770c078/js/private/js_binary.sh.tpl#L250 evaluating to false in that `bazel run` context. Adding a `env = {"BAZEL_BINDIR":"$(BINDIR)"}` to the `js_binary()` produces:

```
C:/users/XXX/XXX/hlezeung/execroot/XXX/bazel-out/x64_windows-opt/bin/XXX/dependencies/javascript/license_checker.sh: line 299: cd: bazel-out/x64_windows-opt/bin: No such file or directory
```

While looking at the code I thought `JS_BINARY__BINDIR` might be relevant here, but it seems unused except for the logging statement in https://github.com/aspect-build/rules_js/blob/86b7aaa3d4bcafaf30bbaf04fba2b7c1d770c078/js/private/js_binary.sh.tpl#L372

Contributor guide

Open the contributing guide

Research direction

Reproduce the Windows failure with `bazel run` on a `js_binary()` and compare it with the working Linux/Mac and `js_run_binary()` cases. Inspect `js/private/js_binary.sh.tpl` around lines 250 and 372, including the `JS_BINARY__BINDIR` logging path, and verify that the fix lets `bazel run` work on Windows without the manual environment override while preserving `js_run_binary()` behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.