Missing dynamic types with Typed Routes + Parallel Routes when doing production build? #63779
Replies: 7 comments 1 reply
-
I had a similar issue and I found a potential workaround but it requires a minor change in I noticed that route/page urls are retrieved by utilizing JS chunks that webpack generates - source. For every chunk there are some connected chunks that are retrieved by calling a Further, I noticed that there are multiple chunk types but all route types are retrieved from However, in some cases, the route path is not retrievable because To temporarily fix the issue on our end I added these lines between for loop and if (mod.constructor.name === 'NormalModule' && !mod.resource) {
mod.resource = chunk.name.replace(/^app/, this.appDir) + '.tsx';
} this will populate the I do not understand the modules and chunk part in order to fully fix the issue but I hope that this helps. Maybe someone from Vercel team can help us here? cc: @leerob NOTE 1: as a result I get type where a page/route is duplicated but since this is a type union it does not matter. NOTE 2: this happened only when parallel route was added; it was working correctly before NOTE 3: I have a setup where inside route group I have a layout and parallel route and there is also a route group nested inside of it. Also there is a catch all route in one case. NOTE 4: grouping the routes in the same way in app and in parallel route made no difference NOTE 5: All sidebar implementetion extend the default one by importing it in the module, not sure if that can cause any issues. |
Beta Was this translation helpful? Give feedback.
-
That's funny because I started getting the same kind of error. And after reading this I noticed that was after I began to use parallel routes. |
Beta Was this translation helpful? Give feedback.
-
@koka0012 the following patch is working for me in next-types-plugin: @@ -521,7 +521,19 @@ class NextTypesPlugin {
if (!chunk.name.startsWith("pages/") && !(chunk.name.startsWith("app/") && (chunk.name.endsWith("/page") || chunk.name.endsWith("/route")))) {
return;
}
- const chunkModules = compilation.chunkGraph.getChunkModulesIterable(chunk);
+
+ // Hack for bug where some routes are missing from typedRoutes generated in prod
+ const chunkModules = [...compilation.chunkGraph.getChunkModulesIterable(chunk)];
+ if (chunkModules.every((mod) => !mod.resource)) {
+ console.warn('Patching broken modules for ', chunk.name);
+ const fakeModules = [...chunk.files]
+ .map((file) => ({
+ resource: _path.default.join(chunk.name.startsWith('app/') ? this.appDir : this.pagesDir, file),
+ layer: _constants.WEBPACK_LAYERS.appRouteHandler,
+ }));
+ chunkModules.push(...fakeModules);
+ }
+
for (const mod of chunkModules){
promises.push(handleModule(mod, assets));
// If this is a concatenation, register each child to the parent ID. |
Beta Was this translation helpful? Give feedback.
-
I have serious concerns about the future of Typed Routes. No updates in quite a while, there’s no indication that it is planned for leaving “experimental” status, and show-stopping bugs like this remain unaddressed. Is it even compatible with turbo yet? Last I checked it was not. |
Beta Was this translation helpful? Give feedback.
-
Are there any updates on this issue? I believe I'm still encountering the same thing as of next@14.2.12. Super annoying issue considering it causes the build step to fail out entirely, meaning I need to either remove all the Route typings and disable |
Beta Was this translation helpful? Give feedback.
-
Ok well, after doing some thorough ripping apart of my repo, I've managed to narrow down why this appears to be happening. It seems like it might have to do with the React Context API. In my instance at least, I am trying to use parallel routes to set up a simple "breadcrumbs" section in shared layouts. I have a folder structure that looks like this in part:
Here is what I am expecting in type StaticRoutes =
// ...
| `/app/admin`
// ...
type DynamicRoutes<T extends string = string> =
// ...
| `/app/${SafeSlug<T>}`
| `/app/${SafeSlug<T>}/order/${SafeSlug<T>}`
// ... Here's an outline of some of the behaviors I'm seeing: Issue with
|
Beta Was this translation helpful? Give feedback.
-
Any news on this issue with parallel routes? |
Beta Was this translation helpful? Give feedback.
-
Summary
Hi all. I'm trying to track down a very tricky bug that occurs when I run a production build. I'm using Next.ja 14.1.4 but it also happens with 14.2.0-canary.44. The conditions:
typedRoutes
DynamicRoutes
types in__next_route_internal_types__
does not include the dynamic route that matches the dynamic path.I've been troubleshooting for hours. I know the following:
page.tsx
, it will work.It has the feel of error that's being caught and not returned to the UI. I'm tempted to say circular dependency but I can't seem to figure out what it doesn't like.
I've been trying to pin this down for hours, almost my entire work day so far, and I can't seem to get it. I'm opening as a discussion because I can't reproduce it in a Codesandbox, which suggests it's something in my codebase, but nothing jumps out.
I would really like to avoid asserting types on this path, it's an important one. It makes me even more hesitant to use Parallel Routes because I don't know what else will pop up once I depend on it.
Has anyone encountered this? Any tips?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions