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

Blob is not instance of Blob #471

Closed
nakleiderer opened this issue May 10, 2022 · 7 comments
Closed

Blob is not instance of Blob #471

nakleiderer opened this issue May 10, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@nakleiderer
Copy link

nakleiderer commented May 10, 2022

It appears that Blob is not an instance of Blob. Here's a minimal repro on StackBlitz using Vitest:
https://stackblitz.com/edit/happy-dom-bug-blob-prototype?file=README.md

This caused the following error when using the @web-std/file package after upgrading from vitest@0.11.0 to vitest@0.12.0

TypeError: Class extends value does not have valid prototype property undefined
Object. node_modules/@web-std/file/dist/src/file.cjs:59:15
Object. node_modules/@web-std/file/dist/src/lib.node.cjs:6:12

I'm not sure if there's also a bug in Vitest or not, but the fact that Blob.prototype is undefined appears to be the root cause. The error only occurs when using the happy-dom environment, so I believe this is the appropriate place to open an issue.

@capricorn86 capricorn86 added the bug Something isn't working label May 16, 2022
@capricorn86
Copy link
Owner

capricorn86 commented May 16, 2022

Thanks for reporting @nakleiderer! 🙂

Not sure exactly what is happening yet, but it seem to be related to the way Vitest is setup. They probably have to fix this.

I ran some tests in your test environment:

// Outputs "false"
console.log(window.globalThis === globalThis)

// Outputs "false"
console.log(window.Blob === globalThis.Blob)

// Outputs "false"
console.log(window.globalThis.Blob === globalThis.Blob)

// Outputs "false"
console.log(Blob === globalThis.Blob)

I will have to look into how Vitest is setup to understand what goes wrong.

The first test is not completely correct. It should be new Blob() instanceof Blob or new globalThis.Blob() instanceof globalThis.Blob.

@capricorn86
Copy link
Owner

@nakleiderer I have reported the bug to Vitest now as I believe it is related to how Vitest implements Happy DOM.

@capricorn86 capricorn86 self-assigned this May 16, 2022
@capricorn86
Copy link
Owner

@nakleiderer this should be solved in the latest version of Vitest 🙂

@rijkvanzanten
Copy link

Heya! Sorry to revive this old issue, but I believe I'm running into the same, if not a similar problem. The original test case you provided now all works as it should:

// Outputs "true"
console.log(window.globalThis === globalThis)

// Outputs "true"
console.log(window.Blob === globalThis.Blob)

// Outputs "true"
console.log(window.globalThis.Blob === globalThis.Blob)

// Outputs "true"
console.log(Blob === globalThis.Blob)

but the following throws an error similar to the OP:

window.URL.createObjectURL(new Blob());
// => The "obj" argument must be an instance of Blob. Received an instance of Blob

Is this related to implementing Document.URL as per #526? I'm a little lost in the nuances between environments and test runners, so apologies if this is a configuration issue/known problem/missing feature/etc..

Thanks!

@nickrum
Copy link

nickrum commented Oct 11, 2022

window.URL.createObjectURL(new Blob());
// => The "obj" argument must be an instance of Blob. Received an instance of Blob

It seems like Vitest is using Node's version of URL, but happy-dom's version of Blob. The error is caused by Node's URL.createObjectURL() receiving an instance of happy-dom's Blob. But even if Vitest would use happy-dom's URL, that wouldn't help much because AFAIK it doesn't yet implement URL.createObjectURL().

@davidortner-ipex
Copy link

I am continuing the work in #520 right now where we will replace the Happy DOM URL with Nodes version of it. Hopefully that will solve this issue then.

@akkie
Copy link

akkie commented Feb 26, 2023

With happy-dom 8.9.0 I face the same issue as @nickrum.

window.URL.createObjectURL(new Blob());
// => The "obj" argument must be an instance of Blob. Received an instance of Blob

Do I miss something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants