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.

Support Dynamic Routes with Next v12 (Cannot find module 'next/dist/server/normalize-page-path')

See original GitHub issue

hello, i have this error :

Test suite failed to run

    Cannot find module 'next/dist/server/normalize-page-path' from 'node_modules/next-router-mock/dist/dynamic-routes/extensions-11.1.js'

    Require stack:
      node_modules/next-router-mock/dist/dynamic-routes/extensions-11.1.js
      components/Breadcrumb/__tests__/BreadcrumbActu.test.js

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:491:11)
      at Object.<anonymous> (node_modules/next-router-mock/src/dynamic-routes/extensions-11.1.ts:9:1)

My version of next.js : “12.1.6”

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
scottrippeycommented, May 6, 2022

I published this as a prerelease! Can you test this out, and lmk if it works?

Version 0.6.8-next12.0

2reactions
kjugicommented, May 5, 2022

As @scottrippey correctly spotted, this file has been moved to the other path in the v12. The provided temporary workaround is almost fine and we have to mark this mock as a virtual like below:

jest.mock(
  'next/dist/server/normalize-page-path',
  () => require('next/dist/shared/lib/page-path/normalize-page-path'),
  { virtual: true } // this is crucial
);

The jest docs about this argument: https://jestjs.io/docs/jest-object#jestmockmodulename-factory-options

The third argument can be used to create virtual mocks – mocks of modules that don’t exist anywhere in the system

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot find module 'next/dist/shared/lib/router/utils ...
OK - I was able to fix this issue by deleting ~/.next. Seems like a build cache bug. Latest version removed routing-items.js but...
Read more >
Nextjs export gives Cannot find module for page
I wanted to export the site with some dynamic routes. My pages folder structure is like below page locales [locale] [slug].js. When I...
Read more >
Advanced Features: Next.js Compiler
Learn about the Next.js Compiler, written in Rust, which transforms and minifies your Next.js application.
Read more >
next-connect - npm
The method routing and middleware layer for Next.js (and many others). ... It does not support error-handling middleware pattern.
Read more >
About Dynamic Routing - WatchGuard Technologies
With static routing, routing tables are set and do not change. If a router on the remote path fails, a packet cannot get...
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