router client file is transpiled incorrectly
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64
Binaries:
Node: 16.11.1
npm: 8.0.0
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.1.5
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
n/a
How are you deploying your application? (if relevant)
n/a
Describe the Bug
The dist/client/router.js file had this code added in version 12.1.5
if (typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) {
Object.assign(exports.default, exports);
module.exports = exports.default;
}
This essentially erases all named exports from the CJS exports object, and instead hangs them all on the default export. This breaks Jest code that’s mocking the useRouter hook.
import * as routerModule from 'next/router';
// ...
jest.spyOn(routerModule, 'useRouter').mockReturnValue(({
pathname: '/foo/bar',
push: pushMockFn,
} as unknown) as useRouter.NextRouter);
now breaks, since routerModule.useRouter
is null, requiring instead
import routerModule from 'next/router';
This fixes the test, but is wrong. useRouter is not a property on the default export (or shouldn’t be) but is rather a named export in that module.
Expected Behavior
CJS exports should match ESM.
To Reproduce
See above
Issue Analytics
- State:
- Created a year ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
Errors transpiling tsx using the create-react-app starter
I'll list the appropriate config files, the offending tsx files, and the first error (as it is common for the other tsx files)....
Read more >Vendor file not transpiled - Get Help - Vue Forum
So I know this is ES6 syntax and I want babel to transpile the necessary packages of my vendor file to ES5. Here...
Read more >Debug Angular apps in production without revealing source ...
If the hash of the property inside the source map doesn't match with the hash of the transpiled file we have generated a...
Read more >Static site generation with React from scratch - LogRocket Blog
Explore building frontend applications in React from scratch using static site generation and the new JSX factory.
Read more >Handling common JavaScript problems - MDN Web Docs
Incorrectly using functions inside loops that iterate with a global ... You can then point these tools at JavaScript files you want to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@arackaf unfortunately for now I have had to roll back to
12.0.7
. The memory leak was what led me here, and it all seems related to the router. I couldn’t get any of the latest versions to build properly, so I’m skipping the hack to get my tests to pass until the larger issues get resolved.This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.