Skip to content

Being able to do import(blobUrls) #47573

Description

@jimmywarting

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...

Activity

  1. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    on Apr 15, 2023
  2. bnoordhuis commented on Apr 17, 2023

    @bnoordhuis
    Member

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

  3. bnoordhuis commented on Apr 17, 2023

    @bnoordhuis
    Member

    Are there WPT tests that cover this?

    To answer my own question: yes, there are

  4. jimmywarting commented on Apr 18, 2023

    @jimmywarting
    Author

    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...

  5. jimmywarting commented on Apr 19, 2023

    @jimmywarting
    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...

  6. github-actions commented on Nov 6, 2023

    @github-actions
    Contributor

    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.

  7. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Nov 6, 2023
  8. github-actions commented on Dec 6, 2023

    @github-actions
    Contributor

    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.

  9. ambyjkl commented on Aug 28, 2024

    @ambyjkl

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

  10. avivkeller commented on Aug 28, 2024

    @avivkeller
    Member

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

  11. 12 remaining items

  12. strogonoff commented on Oct 11, 2024

    @strogonoff

    I’ve been playing with import()ing blob URls successfully in browsers, but in Node a similar approach still doesn’t work. It’d be useful to have this functionality. It looks like the blocker is Blob support in worker threads?

  13. avivkeller commented on Oct 11, 2024

    @avivkeller
    Member

    There's only one caveat: parent blob URLs aren't shared with workers. Once that's resolved, this can move forward.

  14. added
    blockedPRs that are blocked by other issues or PRs.
    on Oct 13, 2024
  15. avivkeller commented on Oct 13, 2024

    @avivkeller
    Member

    IIUC, this can't move forward until #54719 is fixed, as it requires that functionality to work.

  16. strogonoff commented on Oct 14, 2024

    @strogonoff

    I suspect I have to tone down my claim on how useful it’d be useful to simply have import work with blobs in my case, and it has to do with imports within the blob.

    When in the browser, I can register an import map, and those imports become available to the code I await import() as a blob URL. However—correct me if I’m wrong—there is no equivalent mechanism of resolving further imports in Node so far. Unless experimental loader import hooks can somehow do it already (which I suspect not, but haven’t gotten around to trying due to the difficulty of registering them since my command is invoked via npx), it would probably only be possible once import maps are implemented (I know they are on the roadmap for the team working on experimental loader, but I don’t know the status). Maybe I’m wrong?

    For now when it comes to blob imports + import maps I seem to be able to achieve some parity in Node using the good old vm, can’t wait to see how things break…

  17. github-actions commented on Apr 13, 2025

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically 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.

  18. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Apr 13, 2025
  19. PupilTong commented on May 12, 2025

    @PupilTong
    Contributor

    Is there any clean way to workaround this?

  20. strogonoff commented on May 12, 2025

    @strogonoff

    Is there any clean way to workaround this?

    Use vm.SourceTextModule(yourCodeString, { identifier, context }). Requires --experimental-vm-modules flag but works in Node 22.

  21. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on May 13, 2025
  22. github-actions commented on Nov 9, 2025

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically 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.

  23. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Nov 9, 2025
  24. github-actions commented on Dec 9, 2025

    @github-actions
    Contributor

    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.

  25. jimmywarting commented on Dec 9, 2025

    @jimmywarting
    Author

    reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedPRs that are blocked by other issues or PRs.esmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions