-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Wombat breaks native JavaScript modules #116
Comments
@Rich-Harris Thanks for making a note of this. We (Webrecorder project) have actually implemented module detection + different rewriting path in some of our tools (see: webrecorder/wabac.js#101, webrecorder/pywb#810) which does something similar to what you suggest. For example, oldweb.today use our system for the full stack https://oldweb.today/?browser=ruffle#20230327165731/https://kit.svelte.dev/ and https://express.archiveweb.page/#https://kit.svelte.dev/ The IA wayback machine only uses wombat.js from Webrecorder, the rest of their stack is their own proprietary implementation, so they would need to implement the module detection on their end, but it is possible. As long as Svelte doesn't use implicit cross-file globals (see #82), things should generally work. In general, don't think we've seen any replaying Svelte based sites :) |
…b_rewrite_import__(base, url) where base is either empty or the 'import.meta.url' (if used in a module) if base is provided, resolve url with base to ensure relative urls resolve to correct module-relative url bump to 3.5.0 part of fix for issue raised in #116
Good to know, thank you! I contacted IA to let them know about this issue, hopefully they'll be able to implement the module detection. |
#117) * import relative rewrite fix: change __wb_rewrite_import__(url) -> __wb_rewrite_import__(base, url) where base is either empty or the 'import.meta.url' (if used in a module) if base is provided, resolve url with base to ensure relative urls resolve to correct module-relative url bump to 3.5.0 part of fix for issue raised in #116
- support dynamic 'import()' in module or non-module with different base url (presence of import doesn't imply script is in module) - simplify isModule check logic - if script not in module, rewrite dynamic import to '__wb_rewrite_import_('', url), no base resolution - if script is in module, rewrite dynamic import to '__wb_rewrite_import_(import.mata.url, ...)' to pass curr script url as base url - remove duplicate rewrite call! bump to 2.15.4
…cripts (#112) * module rewrite fix: (fix for issue found in webrecorder/wombat#116) - support dynamic 'import()' in module or non-module with different base url (presence of import doesn't imply script is in module) - simplify isModule check logic - if script not in module, rewrite dynamic import to '__wb_rewrite_import_('', url), no base resolution - if script is in module, rewrite dynamic import to '__wb_rewrite_import_(import.mata.url, ...)' to pass curr script url as base url - remove duplicate rewrite call! bump to 2.15.4
…cripts (#112) * module rewrite fix: (fix for issue found in webrecorder/wombat#116) - support dynamic 'import()' in module or non-module with different base url (presence of import doesn't imply script is in module) - simplify isModule check logic - if script not in module, rewrite dynamic import to '__wb_rewrite_import_('', url), no base resolution - if script is in module, rewrite dynamic import to '__wb_rewrite_import_(import.meta.url, ...)' to pass curr script url as base url - remove duplicate rewrite call! bump to 2.15.4
This is now fixed on our end, see this archive |
I was looking at archived copies of https://kit.svelte.dev on the Wayback Machine (example), and discovered that the JavaScript errors when it loads:
This is happening because the file in question is a JavaScript module (i.e. it uses
import
/export
syntax):As the error message says,
import
andexport
can only appear at the top level of a module, not inside a function body. Unfortunately this means that Wombat's transformation breaks every site that uses native modules. Today, these sites are in the minority, but since modules are supported in all modern browsers and many tools emit them automatically, the number is growing rapidly.Afraid I don't have a great suggestion for a solution handy! Perhaps something like this, if
import
/export
is detected in the code......where
xyz123
is a base64-encoded module containing the relevant overrides?The text was updated successfully, but these errors were encountered: