Skip to content

Commit 1d1288a

Browse files
authored
fix: api routes module parsing for recent Next.js releases (#3257)
1 parent 4ee1f30 commit 1d1288a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/build/advanced-api-routes.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,24 @@ const extractConfigFromFile = async (apiFilePath: string, appDir: string): Promi
197197
if (!fileContent.includes('config')) {
198198
return {}
199199
}
200+
201+
try {
202+
// https://github.com/vercel/next.js/pull/85787 introduced need to manually install SWC bindings
203+
// before usage. There are certain cases where Next.js will do that automatically, but to ensure
204+
// it works for all cases, we do install it here as well. If bindings are already installed, this is a no-op.
205+
const installBindingsModule = findModuleFromBase({
206+
paths: [appDir],
207+
candidates: ['next/dist/build/swc/install-bindings'],
208+
})
209+
if (installBindingsModule) {
210+
// eslint-disable-next-line import/no-dynamic-require, n/global-require, @typescript-eslint/no-var-requires
211+
const { installBindings } = require(installBindingsModule)
212+
await installBindings()
213+
}
214+
} catch {
215+
// nothing actionable can be done in case of exceptions
216+
}
217+
200218
const ast = await parseModule(apiFilePath, fileContent)
201219

202220
try {

0 commit comments

Comments
 (0)