bazelbuild / rules_nodejs

NodeJS toolchain for Bazel.

Home Page:https://bazelbuild.github.io/rules_nodejs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yarn install runs on every build

yohcop opened this issue Β· comments

🐞 bug report

Affected Rule

The issue is caused by the rule: rules_nodejs

Is this a regression?

I don't think so, but I'm not sure.

Description

On every build, even a "repeat build" immediately after a successful build, yarn install is re-ran, even if package.json, or yarn.lock are unchanged.

πŸ”¬ Minimal Reproduction

bazel build //some:target # -> success
bazel build //some:target # -> reruns yarn install

🌍 Your Environment

Operating System:

  
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
  

Output of bazel version:

  
$ bazel version
Build label: 5.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Jan 19 14:08:54 2022 (1642601334)
Build timestamp: 1642601334
Build timestamp as int: 1642601334
  

Rules_nodejs version:

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

  
$ cat WORKSPACE | grep -B1 -A3 build_bazel_rules_nodejs
http_archive(
    name = "build_bazel_rules_nodejs",
    sha256 = "e328cb2c9401be495fa7d79c306f5ee3040e8a03b2ebb79b022e15ca03770096",
    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.2/rules_nodejs-5.4.2.tar.gz"],
)
$ cat package.json | grep bazel
    "@bazel/esbuild": "5.4.2",
    "@bazel/jasmine": "5.4.2",
    "@bazel/typescript": "5.4.2",
  

Anything else relevant?

See this trace from the second build which should be near instant.
Screenshot 2022-07-31 11 12 11

You can see the //external:npm running for nearly 17s in my project, out of the 25 total for that build.

This is especially visible and costly with ibazel when the incremental rebuilds should be very small.

See #1627 - are you really running just bazel build twice in a row and see a re-install? Bazel would only do that if something has changed.

Yes, I'm running just 2 bazel builds in a row.
I've checked the linked bug, and added --incompatible_strict_action_env as well as the debug options you suggested on that bug.

All I see in the rebuild explain file is this after the second rebuild:

Build options: --repository_cache='~/.cache/bazel/repository_cache' --incompatible_strict_action_env --strategy='TypeScriptCompile=worker' --define='context=local' --explain=/tmp/rebuild --verbose_explanations --announce_rc
Executing action 'BazelWorkspaceStatusAction stable-status.txt': unconditional execution is requested.

Nothing about nodejs / yarn / npm...

I couldn't find a way to have the line "running yarn install" in some text log (even with --curses=no...), so I recorded a video:

Screen.recording.2022-08-01.00.56.49.webm

Thanks,

I did more digging on this. I couldn't find the real reason I suppose, but adding symlink_node_modules = True to the WORKSPACE file in yarn_install() more or less solved it: it's either still running but is blazing fast, or it's no longer running that yarn install step (I think it's the later, as I can't seem to find the same step in the profile file.) πŸ˜€ .

I'll close for now.