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

Export named 'then' gets called when module is loaded #6685

Closed
6 tasks done
robintown opened this issue Oct 11, 2024 · 1 comment
Closed
6 tasks done

Export named 'then' gets called when module is loaded #6685

robintown opened this issue Oct 11, 2024 · 1 comment

Comments

@robintown
Copy link

Describe the bug

If one of the modules in your project has an exported function named then, Vitest will call this function when loading the module. This can either cause your tests to fail or cause Vitest to hang, depending on whether the function returns or throws.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-qfykda?file=src%2Fbasic.ts

System Info

System:
    OS: Linux 6.6 NixOS 24.11 (Vicuna) 24.11 (Vicuna)
    CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
    Memory: 10.07 GB / 15.26 GB
    Container: Yes
    Shell: 3.7.1 - /run/current-system/sw/bin/fish
  Binaries:
    Node: 22.2.0 - /nix/store/72m3szv59j74b12dmicmayvvlikh65qc-nodejs-22.2.0/bin/node
    npm: 10.7.0 - /nix/store/72m3szv59j74b12dmicmayvvlikh65qc-nodejs-22.2.0/bin/npm
    pnpm: 9.4.0 - /nix/store/xrhk9dzazk4z5s7ba5n136lq25cwf7wz-corepack-nodejs-22.2.0/bin/pnpm
  Browsers:
    Chromium: 129.0.6668.89
  npmPackages:
    @vitejs/plugin-react: ^4.0.4 => 4.2.1 
    vite: ^4.4.9 => 4.5.3 
    vitest: ^2.0.3 => 2.0.3

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

This is a known issue of Vite SSR as we replace static import with dynamic import and needs await on promise. Duplicate of #5122

Node doesn't support such dynamic import either https://stackblitz.com/edit/vitest-dev-vitest-xmakvp?file=repro.js, so I would imagine then export needs to be avoided in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants