vitest: @types/chai conflict with @vitest/expect/dist/chai.d.cts
Describe the bug
since v1.0.0-beta.1 https://github.com/vitest-dev/vitest/commit/5996c8c0
I get the following:
../../node_modules/@types/chai/index.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: Message, ObjectProperty, ChaiPlugin, AssertionArgs, Operator, OperatorComparable, AssertionError, chai
1 declare namespace Chai {
~~~~~~~
../../node_modules/vitest/node_modules/@vitest/expect/dist/chai.d.cts:16:1
16 declare namespace Chai {
~~~~~~~
Conflicts are in this file.
../../node_modules/vitest/node_modules/@vitest/expect/dist/chai.d.cts:16:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: Message, ObjectProperty, ChaiPlugin, AssertionArgs, Operator, OperatorComparable, AssertionError, chai
16 declare namespace Chai {
~~~~~~~
../../node_modules/@types/chai/index.d.ts:1:1
1 declare namespace Chai {
~~~~~~~
Conflicts are in this file.
Found 2 errors in 2 files.
In case it matters, this is an NPM workspace project.
If I delete the file node_modules/vitest/node_modules/@vitest/expect/dist/chai.d.cts everything compiles successfully like before the upgrade to v1.0.0-beta.1.
Reproduction
install and try to compile without skipLibCheck: true in tsconfig
System Info
System:
OS: macOS 13.6.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
npm: 10.2.1 - ~/my-project/node_modules/.bin/npm
npmPackages:
@vitest/coverage-v8: ^1.0.1 => 1.0.1
vite: ^5.0.6 => 5.0.6
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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 open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 13
- Comments: 25 (5 by maintainers)
Commits related to this issue
- Revert to `vitest` 2.0.4 as 2.0.5 has more Chai problems: https://github.com/vitest-dev/vitest/issues/4688 — committed to tidal-music/tidal-sdk-web by osmestad 2 years ago
- Update vitest monorepo to v2 (major) (#156) * Update vitest monorepo to v2 * Remove "--sequence.concurrent" as it caused failure in some packages * Revert to `vitest` 2.0.4 as 2.0.5 has more Ch... — committed to tidal-music/tidal-sdk-web by renovate[bot] 2 years ago
- [EngSys] upgrade dev dependency `typescript` version to `~5.6.2` ***NO_CI*** - replace version to "~5.6.2" - rush update - add `"skipLibCheck": true` for several packages that are affected by https:... — committed to Azure/azure-sdk-for-js by jeremymeng 2 years ago
- [EngSys] upgrade dev dependency `typescript` version to `~5.6.2` ***NO_CI*** - replace version to "~5.6.2" - rush update - add `"skipLibCheck": true` for several packages that are affected by https:... — committed to Azure/azure-sdk-for-js by jeremymeng 2 years ago
Hi, we have also this issue.
We have huge monorepo (~400 packages/rush/pnpm), we are on the mocha/chai/sinon, and we made a try to migrate package by package to vitests. In general tests runs well, but compilation (type checking) on packages where we are using the vitest fails with:
The package itself is not depends on the
@types/chai, but probably somewhere deep in the tree we (or 3partpy dep or dev dep) has such dependency/devDependecy, so it is installed in the tree, but … funny is that thevitestsis causing of loading of@types/chai, during the compilation:tsc --explainFiles says:
In vitest 0.34 there was no such problem as vitest used the
@types/chaiinstead of re-declare it internally.Okay, I just found that adding
skipLibCheck: trueto thetsconfig.json/compilerOptionsis doing the trick.@hi-ogawa I got the upstream type fix merged: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/72101
For what it’s worth, I’ve tried opening a PR against
@types/chaifor this: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/72101I don’t know if it’ll get accepted, since it’ll be breaking for some users who use
chai.should()Okay one hack around this if you don’t want
@vitest/expect’s augmentedchaitypes (ie if you’re migrating from vanillachaior want full control over your ownchaiplugins) is to tweak the shipped type definitions with a hideoustsconfig.jsonhack:Where
vitest-expect.d.tslooks like this:Which is basically the same as the shipped type definition, without the augmented
chaiimport.I see a similar problem after upgrading vitest from 2.0.4 to 2.0.5
Without having
@types/chaiinstalled, I seeAfter installing
@types/chaias suggested, I seeThis seems to be Vitest issue.
Chai is obviously should not be included along with user facing
vitesttype. If Vitest has resemblance with Chai, it should be hidden.the way I see this, any other package that has
@types/chaias a dependency, will cause a conflict with vitest, just because vitest embeds the chai typings. But I could be wrong in my understanding here.