wilsonzlin/esbuild-rs

Not finding node_module modules

juancampa opened this issue · 2 comments

Hi! When I run a simple build command:

      use esbuild_rs::{BuildOptionsBuilder, build, BuildResult, Target, Platform, Engine, Format};
      let mut opts = BuildOptionsBuilder::new();
      opts.bundle = true;
      opts.entry_points.push("main.js".to_string());
      opts.platform = Platform::Node;
      opts.outfile = "out.js".to_string();
      let opts = opts.build();
      let res = futures::executor::block_on(build(opts));
      for warn in res.warnings.as_slice() {
        println!("Warning: {}", warn);
      }
      for err in res.errors.as_slice() {
        println!("Error: {}", err);
      }
      for f in res.output_files.as_slice() {
        println!("Out: {} ({} bytes)", f.path.as_str(), f.data.as_str().len() / 1024);
      }

I get this:

Error: Could not resolve "jsonata" (mark it as external to exclude it from the bundle) [main.js:1:20]

It works fine if I run esbuild via the command line:

esbuild main.js --bundle

So I'm 100% sure the directories/files setup is correct.

I also strace'd it and can see the esbuild opening the right file (i.e.node_modules/jsonata/package.json) but then it continues the search up the directory structure, as if that file wasn't good.

I'm thinking that maybe the version of esbuild-lib is broken. Any chance we can get it updated? Do you have any idea of what could be happening here?

Thanks in advanced!

Another issue that could be causing this is that somehow the options passed to esbuild are not the right ones to bundle correctly, but I didn't find any other relevant option.

Okay I did a big more digging and the issue went away when I specified a main_fields. Closing this.

Thanks for this awesome wrapper 🤍