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

dynamic imports with data: and blob: URIs #6851

Open
dbushell opened this issue Nov 2, 2023 · 1 comment
Open

dynamic imports with data: and blob: URIs #6851

dbushell opened this issue Nov 2, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@dbushell
Copy link

dbushell commented Nov 2, 2023

What version of Bun is running?

1.0.7

What platform is your computer?

Darwin 23.1.0 arm64 arm

What steps can reproduce the bug?

Import a module from a data: URI:

const code = `
function hello() {
  console.log('Hello, World!');
}
export default hello;
`;
const url = `data:text/javascript;base64,${btoa(code)}`;
const mod = await import(url);
mod.default();

Import a module from a blob: URI:

const code = `
function hello() {
  console.log('Hello, World!');
}
export default hello;
`;
const blob = new Blob([code], {type: 'text/javascript'});
const url = URL.createObjectURL(blob);
const mod = await import(url);
URL.revokeObjectURL(url);
mod.default();

What is the expected behavior?

"Hello, World!" should be logged to the console for both techniques.

What do you see instead?

The data: URI example errors:

error: FileNotFound reading "data:text/javascript;base64,CmZ1bmN0aW9uIGhlbGxvKCkgewogIGNvbnNvbGUubG9nKCdIZWxsbywgV29ybGQhJyk7Cn0KZXhwb3J0IGRlZmF1bHQgaGVsbG87Cg=="

The blob: URI example errors:

error: Cannot find package "undefined" from "/[PATH]/test.js"

Additional information

Deno, Firefox, Safari, and Chromium browsers support both techniques. Node supports data: but not blob:. Bun is the only runtime that does not support either.

@dbushell dbushell added the bug Something isn't working label Nov 2, 2023
@jimmywarting
Copy link

If we could, then i would also like to want to throw in the Worker into this issue as well if it's somewhat related. otherwise a new issue could be created just for that.

new Worker('blob:...', { type: 'module' })
new Worker('[data](data:text/javascript;base64,...', { type: 'module' })

( if it still is an issue - it was it the last time i checked )

@Electroid Electroid added enhancement New feature or request and removed bug Something isn't working labels Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants