Version
4.0.2
Reproduction link
https://besenwagen.github.io/vue-router-next-broken-esm-browser-dist/
Steps to reproduce
- Open reproduction URL in a browser
- Observe TypeError in console
What is expected?
The ES module import is resolved.
What is actually happening?
A TypeError is thrown because 'vue' is not resolvable.
Activity
posva commentedon Jan 5, 2021
I'm aware of this but I couldn't find any standard/agreement on how to write an import on a browser module file without forcing the user to use a specific CDN (which I can't)...
One (quite complicated) way to deal with this is to use a service worker to redirect the request for
vue'to a CDN like unpkg or jsdelivr.FYI, in vue router 3 we handled this the same way it is handled here: vuejs/vue-router#2705
I'm open to suggestions!
ghost commentedon Jan 5, 2021
The module URL must be resolved before a request can be initiated (and intercepted). Parsing the message property of a caught exception isn't complicated but madness. Sounds like a job for jQuery. 😂
I saw that after opening this issue, thanks. It is extremely discouraging that the Vue 2 ecosystem did allow coding like it's 2015. ☹
I wish I had any. At this point I fail to see te use case of these build artefacts. The answer is appreciated, anyhow.
ghost commentedon Jan 17, 2021
While it's not possible to intercept bare modules because that fails before there is a request, it turns out it's still possible to create a workaround with a service worker:
It's quite mad, but still better than using the global legacy build for modern development without Node.
posva commentedon Apr 2, 2021
Currently, one needs to use Skypack or https://www.chromestatus.com/feature/5315286962012160 (chrome only). I think this will make sense as a cookbook entry once these topics are more mature
ghost commentedon Apr 12, 2021
Thanks, both were new to me. Cookbook entries and generally more documentation would be great,
esm-browserin a CDN file name raises expectations that are not currently met.kngai commentedon Jun 16, 2021
AimForNaN commentedon Oct 20, 2022
vue-router.esm-browser.prod.jsfor latest version doesn't exist (though I'm not sure if that would remove the dependency).@vue/devtools-apidependency is very inconvenient. While import maps are a quick workaround, I would prefer to be without such a dependency for production.stefnotch commentedon Feb 17, 2023
It looks like every browser, other than old Safari, supports import maps
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
I suppose it would be possible to use the ESM browser module, and add a documentation note about "this needs an import map polyfill if you're targeting Safari".
charlesprescottcollins commentedon Sep 27, 2023
So how does one work around this with skypack?
9mm commentedon Nov 1, 2023
So I'm trying to use vue-router in browser with import maps... how do I workaround these errors?
This is failing with devtools errors?
blacelle commentedon Aug 30, 2024
Until
@vue/devtools-apiis dropped (e.g. into somevue-router.esm-browser.prod.js), one way to move forward is: