Description
I'm trying to use a script built with esbuild as an inline module script in the browser but hitting errors because of relative import paths.
The absolute path to any of my scripts is /assets/${ scriptName }
but the imports are all relative to the current script e.g. import * from './${ scriptName }'
. That works great when scripts are pulled in via <script src=>
but it breaks when used inline. For example, using an inline script on the /login
path in the browser attempts to load the absolute script path /${ scriptName }
or from /account/dashboard
attempts to load /account/${ scriptName }
.
I'm spitballing a solution so take it with a grain of salt, but would you consider an absolute path prefix option? Something like esbuild --absolute-prefix=/assets
maybe? I feel like there's a better way to get to the same solution but I can't think of anything else right now haha
In any case, a solution to my particular issue would turn this output:
import { hasAttribute } from "./chunk.ODYN7WKG.js";
Into this output:
import { hasAttribute } from "/assets/chunk.ODYN7WKG.js";
Thanks for reading and thanks for creating esbuild, it's crazy fast and I use it daily!
Activity