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

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

Closed
6 tasks done
asdfjkalsdfla opened this issue Aug 19, 2023 · 3 comments · Fixed by #4164
Closed
6 tasks done

Comments

@asdfjkalsdfla
Copy link
Contributor

Describe the bug

Starting with 0.34, tests are failing with TypeError: The "obj" argument must be an instance of Blob. Received an instance of Blob. While I can add node Blob in global setup like in #1377 (comment) , this creates inconsistent behaviors for the test vs. web based execution.

Reproduction

https://stackblitz.com/edit/vitejs-vite-aubhih?file=package.json,main.jsx,main.test.jsx,vite.config.js&terminal=dev

System Info

System:
    OS: Linux 5.15 Ubuntu 23.04 23.04 (Lunar Lobster)
    CPU: (8) x64 AMD Ryzen 7 4700U with Radeon Graphics
    Memory: 5.47 GB / 7.45 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.5.1 - ~/.nvm/versions/node/v20.5.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 9.6.2 - ~/node_modules/.bin/npm
    pnpm: 8.6.12 - ~/.local/share/pnpm/pnpm
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.0.1 => 1.0.1
    @vitejs/plugin-react-swc: ^3.3.2 => 3.3.2
    @vitest/coverage-v8: 0.33.0 => 0.33.0
    vite: ^4.4.9 => 4.4.9
    vitest: ^0.34.2 => 0.34.2

Used Package Manager

pnpm

Validations

@stackblitz
Copy link

stackblitz bot commented Aug 19, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@jfairley
Copy link

jfairley commented Aug 28, 2023

I receive the same error originating from URL.createObjectURL.

Works fine in vitest 0.33.x. Breaks in 0.34.x.

Screenshot 2023-08-28 at 9 33 28 AM


Edit: I got around this by stubbing the function in my test setup file.

window.URL.createObjectURL = vi.fn();

Edit2: Arguably better stub...

vi.spyOn(window.URL, "createObjectURL").mockImplementation(() => "http://fake.url");

jbergstroem added a commit to Topsort/analytics.js that referenced this issue Aug 30, 2023
You start in one corner and then you end up painting the entire wall.

This PR achieves the following:
- replaces `npm` with `pnpm`
- replaces `jest` ecosystem with `vitest` (2x speed for me locally)
- enable coverage for tests (we can add codecov as a followup)
- replace `nock`/`isomorphic-fetch` with `msw`
- improve the tests where `fetch` would fail
- modernize `tsconfig.json`
- update CI to use `pnpm` (except releases, will be done separately)
- fix feedback from `tsc` based on updated rulesets
- change how we mount React so we go full 18 mode (it dropped back to
React 17 mode)
- remove the publish script
- switch `ts-loader` for `tslib`
- generate DTS via a vite plugin
- bump all packages to their latest versions (except vitest which has a bug in the `0.34` series)
PR: #197
Refs: vitest-dev/vitest#3985
@sheremet-va
Copy link
Member

So, it worked fine before because Vitest was using jsdom's URL which actually doesn't support createObjectURL. Node 18 now comes with an improved URL implementation which has an unfortunate side effect for the way Vitest worked before with this type of thing - using URL with Node.js API now fails because it checks the instance of the value.

To fix this, we stopped using jsdom's URL, and now only rely on Node.js URL. Looking back, I think this was the wrong decision and we will be reverting it which might introduce more problems when working with Node.js API, but it will be more consistent with how it works in the browser.

To support createObjectURL, you will have to polifyll it yourself.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants