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

vitest browser __vi_esm_0__.default is not a function #4097

Closed
6 tasks done
NicoVogel opened this issue Sep 8, 2023 · 2 comments · Fixed by #5765
Closed
6 tasks done

vitest browser __vi_esm_0__.default is not a function #4097

NicoVogel opened this issue Sep 8, 2023 · 2 comments · Fixed by #5765
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@NicoVogel
Copy link

Describe the bug

When executing the tests, each test fails because of TypeError: __vi_esm_0__.default is not a function.
After reducing it to the minimal reproducible example, I could isolate that the issue is the package pino.

You can find "working" tests here src/browser/working.spec.ts

The mocking does not work, but this is besides this bug

But the same code that uses pino is not able to load it: src/browser/logger.spec.ts

Reproduction

  1. git clone https://github.com/NicoVogel/logger-wrapper
  2. git checkout bug/vitest-browser-vi-esm-0-default-not-a-function
  3. (optional) reopen in dev container
  4. pnpm install
  5. cd packages/logger
  6. pnpm exec vitest -c vitest.browser.ts

System Info

System:
    OS: Linux 6.2 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-1340P
    Memory: 24.36 GB / 31.05 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
    pnpm: 8.6.12 - ~/.nvm/versions/node/v18.17.1/bin/pnpm
  Browsers:
    Chrome: 116.0.5845.140
  npmPackages:
    @vitest/browser: ^0.34.1 => 0.34.1

Used Package Manager

pnpm

Validations

@sheremet-va sheremet-va added bug feat: browser Issues and PRs related to the browser runner and removed pending triage labels Sep 8, 2023
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 7, 2023

I think this is also CJS import issue with browser.slowHijackESM: true and probably considered as a duplicate of #4264, #4505, etc...

As I commented in #4505 (comment), the default became browser.slowHijackESM: false in Vitest v1, so either you can upgrade it or you can manually set slowHijackESM: false in old version.

I tested your repro with slowHijackESM: false and default import works but import { pino } from "pino" is still undefined. It looks like that was issue on Pino side and it seems to be fixed recently in pinojs/pino#1803.
(Interestingly Pino now also exports default.default, so it actually allows it work with slowHijackESM: true as well)

@clocke3
Copy link

clocke3 commented Jan 4, 2024

I am seeing something similar in an application, instead with this error: TypeError: vi_import_0.jsxDEVdescribe is not a function. It looks like it is thrown when trying to use vi.mock.

vi.mock('../../components/shared/table', () => { return { default: () => <div role='table'>table</div> }; });

@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) and removed esm-hijack labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants