Description
I'm aware of #859, but this is not a request to add some sort of __dirname
transformation, but to output a warning for the current behavior.
I'm currently trying to bundle a large Electron app for faster startup time (less require()
calls at runtime). I've run into multiple issues with modules using __dirname
. E.g. I already marked vm2
as external
because it loads files at runtime (#495). In the vm2 case I was lucky enough to get an error at runtime, but really this needs to be a warning when bundling. With __dirname
the bundling effectively changes the semantics of the code. I'm using Piscina to run worker jobs. Naturally I called my worker worker.js
. But after bundling a worker task would never finish and also not error. Turns out Piscina also ships with a worker.js
that loads my worker. After bundling with esbuild Piscina was loading my worker.js instead of it's own. This is a side effect that should definitely cause a warning. Right now I'm considering adding every single dependency as external
and only bundle my own code, because I cannot know for sure if something inside my dependency tree will use __dirname
in unexpected ways and causes funny runtime behavior. With a warning I could only make the packages external that use __dirname
. Assuming I could even easily figure out which package is the problem from the warning (it could be in a file that is a third level dependency of a dependency).
I'm now doing this:
external: Object.keys(JSON.parse(readFileSync('./package.json')).dependencies),
but I'm losing a lot of benefit of the bundling.