sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 126 forks source link

Setting of __dirname breaks some ES modules #540

Open lagnat opened 2 weeks ago

lagnat commented 2 weeks ago

Possibly some wrong assumptions lie ahead..

As discussed in Discord, this is being added to the esbuild in order to workaround modules that are expecting __dirname to be defined. It's my understanding that ion bundles code targeting ESNext and as such __dirname will not be set by nodejs. Any ES module that then tries to define __dirname will fail in ion.

I believe the approach should be that __dirname is never set by ion, unless opted-in, and even that feels out of scope for ion.

Another approach is that ion doesn't set __dirname with const. Still feels wrong to me but could be a good compromise.