Open antoniosZ opened 8 months ago
Why do you have @types/chai
installed?
@sheremet-va they are indirect/nested deps
npm list @types/chai
@my-project
├─┬ @storybook/test@7.6.3
│ └── @types/chai@4.3.5
└─┬ vitest@0.34.6
├─┬ @types/chai-subset@1.3.3
│ └── @types/chai@4.3.5 deduped
└── @types/chai@4.3.5 deduped
I wonder if this should be fixed on storybook side - they are using chai to use @vitest/expect
(form what I gathered here: https://github.com/storybookjs/storybook/issues/17326). It's no longer needed because we bundle it together with @vitest/expect
package because of #2118
We can also try to improve @types/chai
package but I have no idea how to reach maintainers there.
@sheremet-va I removed the @storybook/test
package and I still get the same conflict with the following
$npm list @types/chai
@testing-library/jest-dom@6.1.5
└─┬ vitest@0.34.6
├─┬ @types/chai-subset@1.3.3
│ └── @types/chai@4.3.5 deduped
└── @types/chai@4.3.5
https://github.com/testing-library/jest-dom/blob/main/package.json#L104
seems like to resolve this, everyone else has to remove their @types/chai
dependency or vitest has to remove their bundled typings of chai...
https://github.com/testing-library/jest-dom/blob/main/package.json#L104
seems like to resolve this, everyone else has to remove their
@types/chai
dependency or vitest has to remove their bundled typings of chai...
This is a dev dependency, it's not installed. jest-dom has a peer dependency of Vitest which should just reuse existing one. Try deleting a lockfile and installing everything again.
@sheremet-va I just created a minimal reproduction...
https://stackblitz.com/edit/vitest-dev-vitest-nowys5?file=package.json
if you run in the terminal tsc
you will see the conflict...
@storybook/test
for sure creates the conflict
the way I see this, any other package that has @types/chai
as a dependency, will cause a conflict with vitest, just because vitest embeds the chai typings. But I could be wrong in my understanding here.
one more reproduction, this time with the nightwatch
package, to hopefully demonstrate, that the issue IMO is not isolated to @storybook/test
...
https://stackblitz.com/edit/vitest-dev-vitest-qwc3pw?file=package.json
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:
../../../../common/temp/node_modules/.pnpm/@types+chai@4.3.9/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 {
~~~~~~~
../../../../common/temp/node_modules/.pnpm/@vitest+expect@1.1.0/node_modules/@vitest/expect/dist/chai.d.cts:16:1
16 declare namespace Chai {
~~~~~~~
Conflicts are in this file.
../../../../common/temp/node_modules/.pnpm/@vitest+expect@1.1.0/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 {
~~~~~~~
../../../../common/temp/node_modules/.pnpm/@types+chai@4.3.9/node_modules/@types/chai/index.d.ts:1:1
1 declare namespace Chai {
~~~~~~~
Conflicts are in this file.
Found 2 errors in 2 files.
Errors Files
1 ../../../../common/temp/node_modules/.pnpm/@types+chai@4.3.9/node_modules/@types/chai/index.d.ts:1
1 ../../../../common/temp/node_modules/.pnpm/@vitest+expect@1.1.0/node_modules/@vitest/expect/dist/chai.d.cts:16
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 the vitests
is causing of loading of @types/chai
, during the compilation:
tsc --explainFiles says:
../../../../common/temp/node_modules/.pnpm/@types+chai@4.3.9/node_modules/@types/chai/index.d.ts
Imported via 'chai' from file '../../../../common/temp/node_modules/.pnpm/vitest@1.1.0_@types+node@20.10.3/node_modules/vitest/dist/reporters-O4LBziQ_.d.ts' with packageId '@types/chai/index.d.ts@4.3.9'
Imported via 'chai' from file '../../../../common/temp/node_modules/.pnpm/vitest@1.1.0_@types+node@20.10.3/node_modules/vitest/dist/index.d.ts' with packageId '@types/chai/index.d.ts@4.3.9'
In vitest 0.34 there was no such problem as vitest used the @types/chai
instead of re-declare it internally.
Did someone find a workaround for this? This is very cumbersome…
Okay, I just found that adding skipLibCheck: true
to the tsconfig.json/compilerOptions
is doing the trick.
Trying to fix this in the next patch release of @storybook/test
.
This seems to be Vitest issue.
Chai is obviously should not be included along with user facing vitest
type. If Vitest has resemblance with Chai, it should be hidden.
I see a similar problem after upgrading vitest from 2.0.4 to 2.0.5
Without having @types/chai
installed, I see
node_modules/vitest/dist/chunks/reporters.C_zwCd4j.d.ts:17:23 - error TS7016: Could not find a declaration file for module 'chai'. '.../node_modules/chai/chai.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/chai` if it exists or add a new declaration (.d.ts) file containing `declare module 'chai';`
17 import * as chai from 'chai';
~~~~~~
Found 1 error in node_modules/vitest/dist/chunks/reporters.C_zwCd4j.d.ts:17
After installing @types/chai
as suggested, I see
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/expect/dist/chai.d.cts:16:1
16 declare namespace Chai {
~~~~~~~
Conflicts are in this file.
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.
Errors Files
1 node_modules/@types/chai/index.d.ts:1
1 node_modules/@vitest/expect/dist/chai.d.cts:16
Describe the bug
since v1.0.0-beta.1 https://github.com/vitest-dev/vitest/commit/5996c8c0
I get the following:
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
Used Package Manager
npm
Validations