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

Unable to import commonjs file with default export #2258

Closed
6 tasks done
danez opened this issue Nov 2, 2022 · 6 comments
Closed
6 tasks done

Unable to import commonjs file with default export #2258

danez opened this issue Nov 2, 2022 · 6 comments

Comments

@danez
Copy link
Contributor

danez commented Nov 2, 2022

Describe the bug

This is the same as #2219, but I wasn't able to reopen.

The initial bug was resolved, but I ran into it again when importing a file from node_modules. I tried different things, but I'm not sure why it happens with this one file and not with other cases.

I updated the reproduction example.

Reproduction

https://github.com/danez-labs/vitest-default-commonjs with latest commit

  • npm i
  • npm test

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (16) x64 AMD EPYC 7B13
    Memory: 29.12 GB / 62.80 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.0/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm
  npmPackages:
    vite: ^3.2.2 => 3.2.2 
    vitest: ^0.24.5 => 0.24.5

Used Package Manager

npm

Validations

@sheremet-va sheremet-va added the bug label Nov 2, 2022
@sheremet-va
Copy link
Member

Type definition of @vercel/nft assume it returns default function, and not a default.default function. It also provides __esModule hint for bundlers to look for. By default Vitest respects it, because most of the code is bundled wrongly and users usually don't care, since bundlers fix it for them, when they run code in a browser.

You can disable this behaviour with deps.interopDefault: false option.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
@sheremet-va
Copy link
Member

sheremet-va commented Nov 3, 2022

I guess we can disable it by default, if environment is node 🤔 @antfu what do you think?

@sheremet-va sheremet-va reopened this Nov 3, 2022
@sheremet-va sheremet-va added discussion and removed bug labels Nov 3, 2022
@danez
Copy link
Contributor Author

danez commented Nov 3, 2022

You can disable this behaviour with deps.interopDefault: false option.

Ah yes this worked, thanks.

@Uzlopak
Copy link

Uzlopak commented Nov 14, 2022

This resulted in a regression in fastify/fastify-autoload#277

@tobiasdiez
Copy link

I had the same issue, but it seems to be fixed now (with v. 0.28.3).

@sheremet-va
Copy link
Member

Yes, this is fixed. We tried enabling it by default for node environments, but there were a lot of unexpected issues, so we rolled it back. Vitest always tries to interop default. If you rely on Node behavior, disable deps.interopDefault manually.

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

No branches or pull requests

4 participants