-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
[NEXT-776] commonjs types for next/jest
are incorrect
#37524
Comments
@SukkaW I don't think this is a duplicate - as I indicated in the PR this is still an issue in Next canary (which presumably includes the "fix" in #36824.) I just updated my minimal reproducible example to use |
I see why this is an issue. In Next.js, we add a build flag const { default: nextJest } = require('next/jest');
const nextJest = require('next/jest'); However, you can only do this if you want to have type definition: import nextJest from 'next/jest';
const { default: nextJest } = require('next/jest');
import { default: nextJest } = require('next/jest'); Let me see if we can overcome this. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Just updated the codesandbox repro to use |
@ryami333 Just use The issue can not be fixed by Next.js. It is TypeScript's fault that it does not support exporting both What Next.js can do is to have both named export and default export, which I have brought up in #38503 and is rejected by the Next.js team. |
mine too |
next/jest
are incorrectnext/jest
are incorrect
Verify canary release
Provide environment information
What browser are you using? (if relevant)
Not applicable
How are you deploying your application? (if relevant)
Not applicable
Describe the Bug
Using the boilerplate from the documentation for Setting up Jest (with the Rust Compiler) and with
tsconfig.json#compilerOptions.checkJs
enabled a type-error is generated.The issue appears to be with the commonjs/esm interoperability layer, because:
Known Workarounds
If you bypass the
next/jest
entrypoint and its interoperability layer, and insteadrequire
from thedist/build
folder then it works as expected. Ie.Expected Behavior
There should be no type-errors when using
next/jest
as documented and withcheckJs
enabled.To Reproduce
typescript
andnext
.jest.config.js
) and populate it with the contents of the code-snippet in Setting up Jest (with the Rust Compiler).tsconfig.json
and ensure thatcompilerOption.allowJs
andcompilerOption.checkJs
are both set totrue
, so that thejest.config.js
file is typechecked.See here for a minimal reproducible example.
NEXT-776
The text was updated successfully, but these errors were encountered: