-
-
Notifications
You must be signed in to change notification settings - Fork 428
Dynamic import in client.js breaks app in legacy browsers with v0.28 #1593
Comments
One of the tests does a dynamic import: https://github.com/sveltejs/sapper/blob/master/test/apps/css/src/routes/bar.svelte I guess the question is what's different about your case than the test case |
The test case has a dynamic import inside |
The root cause of this seems to be an issue in Shimport: Rich-Harris/shimport#36 I've raised a PR to revert the original fix since it would break source maps |
The plot thickens! Thanks for this. |
(FYI that Shimport bug is now fixed) |
👍 Yup, this should be good now with Shimport 2.0.5, even if you're using the upcoming version of Sapper that reverts the improper fix in #1595. |
Describe the bug
It can be advantageous to use dynamic imports in client.js, e.g. for browser feature detection and polyfilling:
Prior to Sapper v0.28.0 this worked without issue. In v0.28.0+ using dynamic imports in client.js causes the app to break, i.e. an uncaught error causes JS to cease executing. Looking at the generated output it seems that somehow using a dynamic import means
__inject_styles
is called prior to the line__inject_styles = __inject_styles.default
. The error message is given below.Logs
The following error is displayed in the browser console when using a legacy browser:
To Reproduce
I have included a minimal repro here: https://github.com/rodoch/sapper-client-dynamic-import-repro
This is the default Sapper template with the addition of
@rollup/plugin-json
and@formatjs/intl-getcanonicallocales/polyfill
. The only changes to the app code have been made in client.js.To reproduce:
npm run build
&&node __sapper__/build
.Expected behavior
Including a dynamic import in client.js should not break the app. It is possible to prevent this issue by statically importing the files as below, however this means you are not doing feature detection and you are shipping polyfill code to everybody including browsers that don't need it.
Information about your Sapper Installation:
Browser as described above.
Local, Azure deployment.
Dynamic application
Severity
Not a total blocker, but unnecessarily increases bundle size for all users.
If, for some reason, this is not something which can be supported going forward I recommend it be noted as a breaking change in the Sapper migration docs.
The text was updated successfully, but these errors were encountered: