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

Relative vs. absolute import paths #524

Closed
evanleck opened this issue Nov 12, 2020 · 2 comments
Closed

Relative vs. absolute import paths #524

evanleck opened this issue Nov 12, 2020 · 2 comments

Comments

@evanleck
Copy link

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!

@evanw
Copy link
Owner

evanw commented Nov 12, 2020

I'm spitballing a solution so take it with a grain of salt, but would you consider an absolute path prefix option?

There actually is already a feature for this: the public path setting. It should apply in this case too but it currently doesn't. This is an oversight on my part. I'll fix this in the next release.

@evanw evanw closed this as completed in 7f1781b Nov 12, 2020
@evanleck
Copy link
Author

Cool cool cool, I'd tried that and noticed it didn't work so I figured I was misusing it or something haha

Thanks so much!

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