rules_js icon indicating copy to clipboard operation
rules_js copied to clipboard

react-cra example as mono repo

Open marsh73 opened this issue 1 year ago • 5 comments

I'm able to recreate the example of react-cra when the WORKSPACE and BUILD.bazel file are in the same directory. But when I try and move the source files, along with the BUILD file into a sub directory and update the targets in the WORKSPACE, I'm not able to get it working. Looks like all the examples at https://github.com/aspect-build/bazel-examples have these files in the same root. Do you have an example of what the react-scripts in a subdirectory might look like?

marsh73 avatar Oct 09 '22 22:10 marsh73

@marsh73 What issue were you running into? I got stuck here:

bazel build //examples/cra/...
INFO: Analyzed 12 targets (1 packages loaded, 4682 targets configured).
INFO: Found 12 targets...
ERROR: /Users/ewhauser/working/monorepo/examples/cra/BUILD.bazel:46:22: ReactScripts examples/cra//build failed: (Exit 1): build__js_binary.sh failed: error executing command bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/examples/cra/build__js_binary.sh build

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Could not find a required file.
  Name: index.html
  Searched in: /private/var/tmp/_bazel_ewhauser/c1fee43d9f70be2c9377b78115996411/sandbox/darwin-sandbox/3485/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/public
INFO: Elapsed time: 12.358s, Critical Path: 9.02s
INFO: 6 processes: 6 internal.
FAILED: Build did NOT complete successfully

Because it is searching for public in the root of the execution tree.

ewhauser avatar Oct 15 '22 17:10 ewhauser

Screen Shot 2022-10-16 at 4 11 13 PM

marsh73 avatar Oct 16 '22 23:10 marsh73

I was struggling to get this to work in our production build so i cloned the examples to see if i could make my own mono repo and getting it to work... it feels close but I get the above whether i build or test. cc: @alexeagle

https://github.com/marsh73/rules_js

marsh73 avatar Oct 16 '22 23:10 marsh73

It's looking for package.json in the working directory, so I think you just need to chdir into the package for that relative filesystem lookup to work. https://docs.aspect.build/aspect-build/rules_js/v1.0.0-beta.0/docs/js_binary-docgen.html#js_binary-chdir adding chdir = package_name() to your //cra:build target seems to fix this for me.

(Bazel always runs programs with the monorepo root as the working directory, so rules_js follows that convention as our default for consistency)

alexeagle avatar Oct 16 '22 23:10 alexeagle

@alexeagle you are so quick... thank you... worked perf... going to work on converting our production web build file now.... 🤞

marsh73 avatar Oct 17 '22 00:10 marsh73

@marsh73 Are you all set with this question? If so, can we close it?

cgrindel avatar Oct 25 '22 14:10 cgrindel