question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

window.URL.createObjectURL Blob ERR_INVALID_ARG_TYPE

See original GitHub issue

Describe the bug

In one of my dependencies, window.window.URL.createObjectURL is being called, but it does not like the Blob argument that is being passed in, saying it isn’t a Blob

TypeError: The "obj" argument must be an instance of Blob. Received an instance of Blob

Reproduction

My repro shows the same code in the lib that is failing. It is failing on 0.12.6, before #1340 was released, and on latest.

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 2.29 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 3.1.1 - ~/.yarn/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 101.0.4951.64
    Firefox: 94.0.1
    Safari: 15.4
  npmPackages:
    @vitejs/plugin-react: ^1.3.2 => 1.3.2 
    vite: ^2.9.9 => 2.9.9 
    vitest: 0.12.9 => 0.12.9

Used Package Manager

yarn

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
sheremet-vacommented, May 30, 2022

I see that jsdom doesn’t support URL.createObjectURL at all: issue. If we put jsdom’s URL on global namespace, this call throws an error.

Although Node 16.7 supports it, so you can add to your setupFiles:

import { Blob } from 'buffer'
globalThis.Blob = Blob // use Node.js Blob instead of Jsdom's Blob

However it may create more issue with jsdom API’s 👀

1reaction
kitsunekyocommented, Jul 28, 2022

@mckelveygreg would you mind sharing how you exactly solved it? i’m unable to assign globalThis.fetch to the fetch from node-fetch as the types dont match and it throws a type error for me (using typescript)

Type '(url: string | Request, init?: RequestInit) => Promise<Response>' is not assignable to type '(input: RequestInfo, init?: RequestInit) => Promise<Response>'.
  Types of parameters 'url' and 'input' are incompatible.
Read more comments on GitHub >

github_iconTop Results From Across the Web

URL.createObjectURL() - Web APIs | MDN
The URL.createObjectURL() static method creates a string containing a URL representing the object given in the parameter.
Read more >
window.url.createobjecturl(blob) not working in Edge
I work with the PDFJS Project. I have open blob file in new tap. The below code works in all browsers (Chrome, Firefox,...
Read more >
Using URL.createObjectURL() - Chris Ng - Svbtle
Returns a DOMString containing a unique blob URL, that is a URL with ... createObjectURL(targetFile); mediaElem.src = objectURL; window.URL.
Read more >
Blob
An alternative to URL.createObjectURL is to convert a Blob into a base64-encoded string. That encoding represents binary data as a string of ...
Read more >
Don't build blobs, construct them - Chrome Developers
getBlob ('text/css'); var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = window.URL.createObjectURL(blob);
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found