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

vitest doesn't support TypeScript 5.2's using feature #4183

Open
6 tasks done
knpwrs opened this issue Sep 26, 2023 · 6 comments · May be fixed by #4409
Open
6 tasks done

vitest doesn't support TypeScript 5.2's using feature #4183

knpwrs opened this issue Sep 26, 2023 · 6 comments · May be fixed by #4409
Labels

Comments

@knpwrs
Copy link

knpwrs commented Sep 26, 2023

Describe the bug

TypeScript 5.2 supports an upcoming ES feature, using: https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/

The syntax doesn't get transpiled by vitest, and then tests fail with the following error:

Error: Parse failure: Unexpected token (6:10)
At file: /home/projects/vitest-dev-vitest-uk35mv/test/basic.test.ts
Contents of line 6:     using disposable = {

When I run the files that use the using syntax with https://github.com/esbuild-kit/tsx, it works just fine.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-uk35mv?file=tsconfig.json,test%2Fbasic.test.ts&initialPath=__vitest__/

System Info

System:
    OS: macOS 13.4
    CPU: (12) arm64 Apple M2 Max
    Memory: 2.24 GB / 64.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 20.7.0 - ~/Workspace/letschurch/lets.church/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.1.0 - ~/Workspace/letschurch/lets.church/bin/npm
    pnpm: 8.7.4 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 116.0.5845.187
    Chrome Canary: 117.0.5863.0
    Safari: 16.5
  npmPackages:
    vitest: ^0.34.5 => 0.34.5

Used Package Manager

npm

Validations

@stackblitz
Copy link

stackblitz bot commented Sep 26, 2023

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

knpwrs added a commit to LetsChurch/lets.church that referenced this issue Sep 26, 2023
@sheremet-va
Copy link
Member

Vitest just uses Vite which uses esbuild. Until esbuild is updated in their dependencies (maybe it already is, and you just need to update versions?) you can use the resolutions/overrides field:

For pnpm:

{
  "overrides": {
    "esbuild": "^0.19.3"
  }
}

For yarn:

{
  "resolutions": {
    "esbuild": "^0.19.3",
  }
}

@knpwrs
Copy link
Author

knpwrs commented Sep 29, 2023

I thought esbuild was only used for dependencies, not for application code? In any case, that override doesn't appear to fix the issue. Also, tsx uses an older version of esbuild than that override and the using syntax works just fine in tsx.

@juanrgm
Copy link

juanrgm commented Oct 25, 2023

Vitest uses rollup for application code, and rollup uses acorn.

rollup/rollup#5113

@nedsalk
Copy link

nedsalk commented Oct 26, 2023

I fixed this issue by setting esbuild's target to es2022:

import { defineConfig } from 'vitest/config';

export default defineConfig({
  esbuild: { target: 'es2022' },
});

@sheremet-va
Copy link
Member

The current workaround is to use @nedsalk's config. The issue should be fixed when Vitest 1.0 is released.

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

Successfully merging a pull request may close this issue.

4 participants