Skip to content

__vite_ssr_dynamic_import__ doesn't coerce import(specifier) to a string #3429

@jcbhmr

Description

@jcbhmr

Describe the bug

If you pass in a non-string into an import statement when using Vitest, you'll get a cryptic "id.startsWith is not a function" message. I think this is due to the custom __vite_ssr_dynamic_import__() function that seems to replace all import() stuff not properly doing myArg = `${myArg}`; like browsers and Node.js do natively to make sure the arg is a true string.

Reproduction

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

image

System Info

~/projects/vitest-dev-vitest-mamgrv 1m 15s
❯ npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers
success Install finished in 0.928s


  System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @vitest/ui: latest => 0.31.1 
    vite: latest => 4.3.8 
    vitest: latest => 0.31.1 


### Used Package Manager

npm

### 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions