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

Injected script wrapper code breaks ES6 Module JS files #262

Open
rajsite opened this issue Dec 2, 2023 · 1 comment
Open

Injected script wrapper code breaks ES6 Module JS files #262

rajsite opened this issue Dec 2, 2023 · 1 comment

Comments

@rajsite
Copy link

rajsite commented Dec 2, 2023

See how the following page fails to render: https://web.archive.org/web/20231202192545/https://nimble.ni.dev/storybook/

The issue is that the page uses modern es6 modules in the js files. For example in:
https://web.archive.org/web/20231202192545/https://nimble.ni.dev/storybook/sb-manager/runtime.js

Notice how archive.org is inserting content into the file that wraps the entire file in a block:

image
The issue is that file is a standard es6 JS file and is using the import statement. All import statements in standard JS files need to be top-level, see the mdn documentation.

import declarations can only be present in modules, and only at the top-level (i.e. not inside blocks, functions, etc.).

The script inserted by archive.org moves the import from the top-level to the inside of a block by wrapping it in curly braces. This causes the JS file to fail to run with a SyntaxError.

@rajsite rajsite changed the title Injected script wrapper code breaks JS files Injected script wrapper code breaks ES6 Module JS files Dec 2, 2023
@gm112
Copy link

gm112 commented Jan 24, 2025

This not only impacts import statements, but also exports. I don't believe there's a workaround until wayback can handle type="module" on script tags, or use heuristics to detect if a .js file is using ES Module semantics.

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