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

Default import doesn't work with vitest browser mode #4264

Closed
quolpr opened this issue Oct 6, 2023 · 1 comment · Fixed by #4414
Closed

Default import doesn't work with vitest browser mode #4264

quolpr opened this issue Oct 6, 2023 · 1 comment · Fixed by #4414

Comments

@quolpr
Copy link

quolpr commented Oct 6, 2023

Describe the bug

Here is the test:

import React from "react";
import { expect, it } from "vitest";

it("works", () => {
  expect(React).not.toBe(undefined);
});

It will fail in browser mode, but will run in CLI mode. I suspect the error happen cause react still using CJS packages and default export is not configured properly for vitest.

Reproduction

https://github.com/quolpr/vitest-browser-default-import-bug

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.77 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.asdf/installs/nodejs/16.16.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/installs/nodejs/16.16.0/.npm/bin/yarn
    npm: 8.11.0 - ~/.asdf/plugins/nodejs/shims/npm
    Watchman: 2023.09.04.00 - /opt/homebrew/bin/watchman
  npmPackages:
    @vitejs/plugin-react-swc: ^3.4.0 => 3.4.0
    @vitest/browser: ^0.34.6 => 0.34.6
    vite: ^4.4.5 => 4.4.11
    vitest: ^0.34.6 => 0.34.6


### Used Package Manager

yarn

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@quolpr
Copy link
Author

quolpr commented Oct 8, 2023

I can even confim that react examples in example/react stops working after I change config to this:

export default defineConfig({
  test: {
    globals: true,
    browser: {
      name: "chromium",
      provider: "playwright",
      enabled: true,
    },
  },
});

The error is such:

image image

I can also confirm that it doesn't work with webdriverio too

@quolpr quolpr changed the title CJS synthetic default export doesn't work in browser mode Default import doesn't work with vitest browser mode Oct 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 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.

1 participant