question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

router client file is transpiled incorrectly

See original GitHub issue

Verify 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:closed
  • Created a year ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Bonitiscommented, May 11, 2022

@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.

0reactions
github-actions[bot]commented, Jun 17, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found