Skip to content

The parameter name it causes auto import to incorrectly import vitest #587

@tbontb-iaq

Description

@tbontb-iaq

Describe the bug

When I have a local library added to auto-import, and there is a function in the library, and one of the function's parameters is named as it, auto-import will import vitest's it, which will cause serious errors.

This code:

export default {
  func: (it: unknown) => {
    console.log(it)
  },
}

Will be transfered to this by auto import:

import { it } from "/node_modules/.vite/deps/vitest.js?v=0ceb812e";
export default {
  func: (it) => {
    console.log(it);
  }
};

Which results this error:

Error: Vitest failed to access its internal state.

One of the following is possible:
- "vitest" is imported directly without running "vitest" command
- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)
- "vitest" is imported inside Vite / Vitest config file
- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues

Reproduction

See above

System Info

Omit

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions