Visitar URL original
Being able to do `import(blobUrls)` · Issue #47573 · nodejs/node · GitHub
The Wayback Machine - https://web.archive.org/web/20240901125512/https://github.com/nodejs/node/issues/47573
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

Being able to do import(blobUrls) #47573

Open
jimmywarting opened this issue Apr 15, 2023 · 12 comments · May be fixed by #54647
Open

Being able to do import(blobUrls) #47573

jimmywarting opened this issue Apr 15, 2023 · 12 comments · May be fixed by #54647
Assignees
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js.

Comments

@jimmywarting
Copy link

jimmywarting commented Apr 15, 2023 •

What is the problem this feature will solve?

tried doing:

code = 'console.log("hi")'
blob = new Blob([code], { type: 'text/javascript' })
url = URL.createObjectURL(blob)
import(url)

but failed with:

Only URLs with a scheme in: file and data are supported by the default ESM loader. Received protocol 'blob:'

What is the feature you are proposing to solve the problem?

being able to import dynamic generated code...

What alternatives have you considered?

converting it to a data: url works as a work around...

@jimmywarting jimmywarting added the feature request Issues that request new features to be added to Node.js. label Apr 15, 2023
@MoLow MoLow added the esm Issues and PRs related to the ECMAScript Modules implementation. label Apr 15, 2023
@bnoordhuis
Copy link
Member

Does importing a blob work in other JS runtimes? It doesn't seem to in Firefox. Are there WPT tests that cover this?

@bnoordhuis
Copy link
Member

Are there WPT tests that cover this?

To answer my own question: yes, there are

@jimmywarting
Copy link
Author

jimmywarting commented Apr 18, 2023 •

Does importing a blob work in other JS runtimes?

Yes... i have done it many times in browsers to create dynamic code that i then import...

there are many other developer who dose this too. things like sql.js and JSZip think both are creating a hybrid solution that takes it's own minified source code and create a separate thread in order to not block havy calculations.

kinda like:

function ctx() { ... }
const blob = blob([ctx.toString(), `${ctx.name}()`])
const url = URL.createObjectURL(blob)

import(url)
new Worker(url)

works OK, as long as the function is "pure" and don't references any variable outside of it's own function
But i guess it's a bit unusual to do: import(blobURL) then to create dynamic web workers.

JSFiddle and other code playgrounds certainly benefit of using import(blobUrl) if there is code that uses import x from xyz syntax


I just worked around this issue in my web worker polyfill
I created a custom loader and basically run NodeJS with: node --loader ./resolver.js app.js

And b/c blob urls are not working via cross threads: #46557
then i had to resort to using BroadcastChannel to request all threads if they have any references to those blobs.

so i guess ☝️ is a blocker...

@jimmywarting
Copy link
Author

I could add to that i would also like to be able to do:

const url = URL.createObjectURL(blob)
new worker_threads.Worker(url, { type: 'module' })

but that maybe will be a own issue in itself...

Copy link
Contributor

github-actions bot commented Nov 6, 2023

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Nov 6, 2023
Copy link
Contributor

github-actions bot commented Dec 6, 2023

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
@Ambyjkl
Copy link

Ambyjkl commented Aug 28, 2024

@RedYetiDev I would like this as well. All web browsers support this, Deno supports this, Bun supports this. Node is the black sheep

@RedYetiDev
Copy link
Member

RedYetiDev commented Aug 28, 2024 •

Hey, I don't think I've interacted with this issue yet, was there a specific reason for pinging me?

@Ambyjkl
Copy link

Ambyjkl commented Aug 28, 2024

Hey, I don't think I've interacted with this issue yet, was there a specific reason for pinging me?

It said that you removed this from Node.js feature requests, so I thought you would be the one to contact

@RedYetiDev
Copy link
Member

Ahh okay, no problem, I was doing a bit of cleanup.

@RedYetiDev RedYetiDev removed the stale label Aug 28, 2024
@RedYetiDev RedYetiDev reopened this Aug 28, 2024
@RedYetiDev RedYetiDev self-assigned this Aug 29, 2024
@RedYetiDev
Copy link
Member

I've been working on this a bit today, and I think I almost have it down. I've assigned myself to prevent other users from doing work thats already been done, I'd hate to see anyone's time go to waste.

@RedYetiDev RedYetiDev linked a pull request Aug 29, 2024 that will close this issue
@RedYetiDev
Copy link
Member

#54647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js.
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

5 participants