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

esbuild: error: Could not resolve "react" (mark it as external to exclude it from the bundle) #2503

Closed
karlhepler opened this issue Mar 4, 2021 · 2 comments · Fixed by #2506
Assignees
Labels

Comments

@karlhepler
Copy link

karlhepler commented Mar 4, 2021

This issue follows this issue.

I was able to get it past the --preserve-symlinks error, but now I have a new error and I'm not sure what to do about it.

I feel like the npm modules should be able to be bundled. It kind of defeats the purpose for me if I can't bundle the npm modules.

Error

INFO: Invocation ID: 3c7403f6-0e2d-4c23-90b5-4da687d6b7c5
INFO: Analyzed target //:bundle (2 packages loaded, 8 targets configured).
INFO: Found 1 target...
ERROR: workspace/BUILD.bazel:27:8: Bundling Javascript index.mjs [esbuild] failed (Exit 1) esbuild failed: error executing command external/esbuild_darwin/bin/esbuild --bundle bazel-out/darwin-fastbuild/bin/index.mjs --sourcemap --preserve-symlinks '--platform=browser' '--target=es2015' '--log-level=info' ... (remaining 6 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
 > bazel-out/darwin-fastbuild/bin/index.mjs: error: Could not resolve "react" (mark it as external to exclude it from the bundle)
    1 │ import React from "react";
      ╵                   ~~~~~~~

 > bazel-out/darwin-fastbuild/bin/index.mjs: error: Could not resolve "react-dom" (mark it as external to exclude it from the bundle)
    2 │ import ReactDOM from "react-dom";
      ╵                      ~~~~~~~~~~~

2 errors
Target //:bundle failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.516s, Critical Path: 0.20s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Things I tried

(reference my setup here)

  • created es5_sources filegroup and used that in deps instead of :lib
  • added @npm//react and @npm//react-dom to deps
  • changed the devmode_ and prodmode_ module and target to esnext and es2015, respectively
@karlhepler
Copy link
Author

karlhepler commented Mar 4, 2021

Here's a link to my repo

https://github.com/karlhepler/bazel-esbuild

@takegine
Copy link

how do you resolve it? I got the error too.

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

Successfully merging a pull request may close this issue.

3 participants