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

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

Closed
jcbhmr opened this issue May 22, 2023 · 1 comment · Fixed by #3430
Closed

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

jcbhmr opened this issue May 22, 2023 · 1 comment · Fixed by #3430

Comments

@jcbhmr
Copy link
Contributor

jcbhmr commented May 22, 2023

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.
@stackblitz
Copy link

stackblitz bot commented May 22, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 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

Successfully merging a pull request may close this issue.

2 participants