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

react-cra example as mono repo #507

Open
marsh73 opened this issue Oct 9, 2022 · 8 comments
Open

react-cra example as mono repo #507

marsh73 opened this issue Oct 9, 2022 · 8 comments
Labels
example New example or update to existing example

Comments

@marsh73
Copy link

marsh73 commented Oct 9, 2022

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?

@cgrindel cgrindel added the question This issue is a question. Close the loop with documentation? label Oct 10, 2022
@ewhauser
Copy link

@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.

@marsh73
Copy link
Author

marsh73 commented Oct 16, 2022

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

@marsh73
Copy link
Author

marsh73 commented Oct 16, 2022

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

@alexeagle
Copy link
Member

alexeagle commented Oct 16, 2022

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)

@marsh73
Copy link
Author

marsh73 commented Oct 17, 2022

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

@cgrindel
Copy link
Contributor

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

@gregmagolan
Copy link
Member

@marsh73 I gave the CRA example an upgrade recently: https://github.com/aspect-build/bazel-examples/tree/main/react-cra. A added jest test targets, eslint targets, separate ts_project transpilation targets for application code and specs. The react-scripts "build" target no longer does any transpilation since that is done in fine grained ts_project targets.

@gregmagolan
Copy link
Member

I'll make another PR to re-organize the code so it looks more like it would in a monorepo with the react-scripts build target not in the root BUILD file

@gregmagolan gregmagolan added example New example or update to existing example and removed question This issue is a question. Close the loop with documentation? labels Feb 4, 2023
@gregmagolan gregmagolan moved this to 🔖 Ready in Open Source Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example New example or update to existing example
Projects
No open projects
Status: On Deck
Development

No branches or pull requests

5 participants