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

How to configure build to not use node modules #3540

Closed
simod opened this issue Dec 12, 2023 · 4 comments
Closed

How to configure build to not use node modules #3540

simod opened this issue Dec 12, 2023 · 4 comments

Comments

@simod
Copy link

simod commented Dec 12, 2023

Dears,

I'm trying to bundle an app that includes a library which imports http, https, zlib and url from node.
In my previous setup (react-app-rewired) I used to have an override file with this configuration
module.exports = function override(config, env){
config.resolve.fallback = {
http: false,
https: false,
zlib: false,
url: false
}}

I've been experimenting quite a lot but can't figure out how to do it with ESBuild.
Would you have any hints?

@evanw
Copy link
Owner

evanw commented Dec 12, 2023

“Not use node modules” could mean many things, and esbuild has many ways of altering things.

You’d have to be more specific for me to answer your question. A good start would be to follow the issue reporting instructions that you deleted when posting this issue:

When reporting a bug or requesting a feature, please do the following:

  • Describe what esbuild is doing incorrectly and what it should be doing instead.

  • Provide a way to reproduce the issue. The best way to do this is to demonstrate the issue on the playground (https://esbuild.github.io/try/) and paste the URL here. A link to a minimal code sample with instructions for how to reproduce the issue may also work. Issues without a way to reproduce them may be closed.

In addition, here are some documentation links you may find helpful:

@simod
Copy link
Author

simod commented Dec 12, 2023

@evanw thanks for your answer.
Here some clarifications:
a library I use (Cesium) requires the mentioned modules. In the past method adding the setting I mentioned to the webpack.config override did the job. I'm now migrating to esbuild and I've been able to achieve a build using the following command:

esbuild src/index.js --outdir=public/static --bundle --sourcemap --servedir=public --loader:.js=jsx --external:https --external:http --external:zlib --external:url

However the error now pops up in another library (geotiff.js) "Uncaught Error: Dynamic require of "http" is not supported". It seems that this library is acting as it is in a node environment and not in a browser.

Since geotiff has the "browser:{http: false}" in the package.json, I'm wondering if this error could be due to esbuild or not.

Thanks

@evanw
Copy link
Owner

evanw commented Dec 18, 2023

The geotiff package has its exports set up like this (in package.json):

  "exports": {
    ".": {
      "import": "./dist-module/geotiff.js",
      "require": "./dist-node/geotiff.js",
      "browser": "./dist-browser/geotiff.js"
    }
  },

That looks like a problem with that package to me. The browser condition will never match because in practice, every import of that library will either be an import or a require and the exports field works by going with the first entry that matches. I assume fixing the package to actually map to the browser build when targeting the browser will fix the problem of it trying to use node libraries.

This is a problem with that package, not with esbuild. The right issue to track that problem might be geotiffjs/geotiff.js#396.

@evanw
Copy link
Owner

evanw commented Dec 29, 2023

I'm closing this issue because this is a problem in another package.

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants