Closed rgembalik closed 1 year ago
Yea, same issue with the latest 13.5.1
the router-context file it previously imported from the next/dist has been renamed to router-context.shared-runtime
After updating the import statement from import { RouterContext } from 'next/dist/shared/lib/router-context';
to import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime';
fixed the issue for me.
If you want to fix your tests while this gets fixed, I used this workaround in my global jest setup:
jest.mock(
'next/dist/shared/lib/router-context',
() => jest.requireActual('next/dist/shared/lib/router-context.shared-runtime'),
{ virtual: true },
);
Thanks for this great library and for working on support for the new next router. I'm amazed that by stacking workarounds it's still able to work.
I had the same issue when upgrading to Next.js 13.5.1. Another workaround is to add a module mapping to the jest.config
:
moduleNameMapper: {
'next/dist/shared/lib/router-context':
'next/dist/shared/lib/router-context.shared-runtime',
},
As @ra-lfaro mentioned, the source of the issue is the renaming of the file next/dist/shared/lib/router-context
in this commit in Next.js: https://github.com/vercel/next.js/commit/5217e7eb0698947a95a2d6410f4a36c482be406a#diff-f7b79c420a8c291fefaa78163620fa1abaad67a98138fbea666b9d25d95a2331
I was trying to do the same using vitest, but there is neither moduleNameMapper
nor {virtual: true}
for the vi.mock
. I checked the alias
in vitest.config
but with no luck. Any help here would be super appreciated 🙏
@scottrippey - now that next 13.5 was released - would you be open for a PR which changes the import here:
and here:
See #105
I will get that PR merged soon!
FWIW, this has been a problem before, and I've tried working with Vercel to improve the testability. I've tried using my internal contacts with their org, and still made no progress. Please upvote this discussion if you'd like to help bring attention to this annoying issue! https://github.com/vercel/next.js/discussions/38248
Any idea how to make the next-router-module work with the next@13.4.20-canary.20 or later?
I'm getting this error: