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

ReferenceError: __vite_ssr_import_1__ is not defined when a spec imports preact/compat #367

Closed
6 tasks done
molily opened this issue Dec 29, 2021 · 0 comments
Closed
6 tasks done

Comments

@molily
Copy link
Contributor

molily commented Dec 29, 2021

Describe the bug

Hello, first of all, thank you for this great library!

I have an existing project that uses Vite, Preact and Jest. This worked fine so far with thanks to @preact/preset-vite. I’m currently adapting the specs to run them with vitest.

I have a simple Preact component that imports memo from preact/compat and a corresponding spec.

See
https://github.com/molily/vitest-test/blob/main/src/MemoMessage.jsx
https://github.com/molily/vitest-test/blob/main/src/MemoMessage.test.jsx

When running vitest, I get this error:

☀ npx vitest run

 RUN  /Users/molily/projekte/vitest-test

 √ src/Message.test.jsx (1)
 ❯ src/MemoMessage.test.jsx (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/MemoMessage.test.jsx [ src/MemoMessage.test.jsx ]
ReferenceError: __vite_ssr_import_1__ is not defined
 ❯ node_modules/.pnpm/[email protected]/node_modules/preact/compat/dist/compat.module.js:9:712

 ❯ async directRequest file:/Users/molily/projekte/vitest-test/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/worker.js:9487:5
 ❯ async cachedRequest file:/Users/molily/projekte/vitest-test/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/worker.js:9516:12
 ❯ async src/MemoMessage.jsx:3:31
 ❯ async directRequest file:/Users/molily/projekte/vitest-test/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/worker.js:9487:5
 ❯ async cachedRequest file:/Users/molily/projekte/vitest-test/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/worker.js:9516:12
 ❯ async src/MemoMessage.test.jsx:7:31
 ❯ async directRequest file:/Users/molily/projekte/vitest-test/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/worker.js:9487:5
 ❯ async cachedRequest file:/Users/molily/projekte/vitest-test/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/worker.js:9516:12
 ❯ async collectTests node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest/dist/entry.js:1342:7

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Test Files  1 failed | 1 passed (2)
     Tests  1 passed (1)
      Time  1.41s (in thread 14ms, 10419.68%)

The component spec which does not include preact/compat passes (Message.test.jsx).

Any ideas why this happens with vitest while vite (dev and prod build) works fine?

My uneducated guess is that vitest clashes with the code transformations in @preact/preset-vite, including @prefresh/vite for HMR. I’ve copied @preact/preset-vite to remove prefresh. See vite-no-prefetch.config.js. But alas, vitest -c vite-no-prefetch.config.js throws the same error.

I’m happy to forward this problem to the Preact team if there is anything they can do.

Thank you very much! 💖

Reproduction

See:
https://github.com/molily/vitest-test

$ pnpm install
$ npx vitest run

System Info

System:
    OS: macOS 12.1
  Binaries:
    Node: 16.13.1 - /usr/local/Cellar/node@16/16.13.1/bin/node
    npm: 8.1.2 - /usr/local/Cellar/node@16/16.13.1/bin/npm
  npmPackages:
    vite: ^2.7.9 => 2.7.9
    vitest: ^0.0.122 => 0.0.122

Used Package Manager

pnpm

Validations

JakeGinnivan pushed a commit to JakeGinnivan/vitest that referenced this issue Jan 8, 2022
chaii3 pushed a commit to chaii3/vitest that referenced this issue May 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant