I am trying to build a Stencil library, but I am getting the following error from Jest.
stencil-library:dev: > stencil build --dev --watch --serve
stencil-library:dev:
stencil-library:dev: [09:03.6] @stencil/core
stencil-library:dev: [09:03.8] v2.16.1 🎻
stencil-library:dev: [09:06.4] build, stencil-demo, dev mode, started ...
stencil-library:dev: [09:06.4] transpile started ...
stencil-library:dev: [09:09.8] transpile finished in 3.37 s
stencil-library:dev: [09:10.1] build, stencil-demo, dev mode, started ...
stencil-library:dev: [09:10.1] transpile started ...
stencil-library:dev: [09:13.4] transpile finished in 3.23 s
stencil-library:dev:
stencil-library:dev: [ ERROR ] TypeScript: ../../node_modules/@types/jest/index.d.ts:691:15
stencil-library:dev: Interface 'Matchers<R, T>' incorrectly extends interface
stencil-library:dev: 'TestingLibraryMatchers<(str: string) => any, R>'.The types returned
stencil-library:dev: by 'toHaveAttribute(...)' are incompatible between these types.Type
stencil-library:dev: 'void' is not assignable to type 'R'.'R' could be instantiated with
stencil-library:dev: an arbitrary type which could be unrelated to 'void'.
stencil-library:dev:
stencil-library:dev: L690: // should be R extends void|Promise<void> but getting dtslint error
stencil-library:dev: L691: interface Matchers<R, T = {}> {
stencil-library:dev: L692: /**
stencil-library:dev:
stencil-library:dev: [09:13.4] build failed, watching for changes... in 3.25
It appears that Stencil is trying to invoke Jest after transpiling and that's where TypeScript errors out. Any clue what's going on?
My repository is here: https://github.com/nareshbhatia/stencil-demo
To reproduce the error, simply run the following:
npm install
# Run the stencil-library in the browser (http://localhost:3333)
npm run dev
Answering my own question...
The issue was narrowed down to a stencil dependency: @stencil/react-output-target. This library has dependencies to older versions of React and React Testing Library:
"devDependencies": {
"@types/react": "^16.7.0",
"@types/react-dom": "^16.7.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-testing-library": "^7.0.0"
}
I downgraded React from v18 to v17 and dropped react-testing-library completely to make this work.