-
Notifications
You must be signed in to change notification settings - Fork 185
Fix Next 16.1 not including skipTrailingSlashRedirect #1072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
e02abbe
be45424
d3f0b44
5cc37c9
403e500
4c1f499
6e21c71
5bdc712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@opennextjs/aws": patch | ||
| --- | ||
|
|
||
| Fix for Next 16.1 config |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { buildSync } from "esbuild"; | ||
| import type { CodePatcher } from "../codePatcher"; | ||
|
|
||
| export const patchNextConfig: CodePatcher = { | ||
| name: "patch-next-config", | ||
| patches: [ | ||
| { | ||
| pathFilter: /required\-server\-files\.json$/, | ||
| versions: ">=16.1.0", | ||
| patchCode: async ({ code, buildOptions }) => { | ||
| // Find the next.config file with any supported extension | ||
| const possibleExtensions = [".ts", ".mjs", ".js", ".cjs"]; | ||
| let configPath: string | undefined; | ||
| let configExtension: string | undefined; | ||
|
|
||
| for (const ext of possibleExtensions) { | ||
| const testPath = path.join(buildOptions.appPath, `next.config${ext}`); | ||
| if (fs.existsSync(testPath)) { | ||
| configPath = testPath; | ||
| configExtension = ext; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!configPath || !configExtension) { | ||
| throw new Error("Could not find next.config file"); | ||
| } | ||
|
|
||
| let configToImport: string; | ||
|
|
||
| // Only compile if the extension is .ts | ||
| if (configExtension === ".ts") { | ||
| buildSync({ | ||
| entryPoints: [configPath], | ||
| outfile: path.join(buildOptions.tempBuildDir, "next.config.mjs"), | ||
| bundle: true, | ||
| format: "esm", | ||
| platform: "node", | ||
| }); | ||
| configToImport = path.join( | ||
| buildOptions.tempBuildDir, | ||
| "next.config.mjs", | ||
| ); | ||
| } else { | ||
| // For .js, .mjs, .cjs, use the file directly | ||
| configToImport = configPath; | ||
| } | ||
|
|
||
| // In next 16.1+ we need to add `skipTrailingSlashRedirect` manually because next removes it from the config | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: do you think this should be reported as an issue on the Next repo?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could, but I think they did it on purpose. Looks like they use define for that now, and I checked, it is defined in the adapter output |
||
| const originalConfig = (await import(configToImport)).default; | ||
| const config = JSON.parse(code); | ||
| if (config.config.skipTrailingSlashRedirect === undefined) { | ||
| config.config.skipTrailingSlashRedirect = | ||
| originalConfig.skipTrailingSlashRedirect ?? false; | ||
| } | ||
| return JSON.stringify(config, null, 2); | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like
.mtsis also supported from the Next repo.line 34 should be updated below as well.
Maybe use
{extension: isTypeScript}instead of an array here?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://nextjs.org/docs/pages/api-reference/config/typescript#for-commonjs-projects-default also mentions
.ctsin a note, not sure if really needed?