Open ryami333 opened 2 years ago
Duplicated https://github.com/vercel/next.js/issues/36534.
The issue has been fixed in https://github.com/vercel/next.js/pull/36824.
@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 https://github.com/vercel/next.js/pull/36824.)
I just updated my minimal reproducible example to use 12.1.7-canary
and it is indeed still a problem.
I just updated my minimal reproducible example to use
12.1.7-canary
and it is indeed still a problem.
I see why this is an issue.
In Next.js, we add a build flag interopClientDefaultExport
to enable a hack for default export. It allows you to import the module in both ways:
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.
Also facing the same issue.
Just updated the codesandbox repro to use 12.2.6-canary
and confirmed that it's still not working.
@ryami333 Just use default
export as a workaround.
The issue can not be fixed by Next.js. It is TypeScript's fault that it does not support exporting both module.exports
and module.exports.default
. You should blame TypeScript for that.
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
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