diff --git a/packages/runtime/src/helpers/config.ts b/packages/runtime/src/helpers/config.ts index 8db64bdbbf..10717ca3a8 100644 --- a/packages/runtime/src/helpers/config.ts +++ b/packages/runtime/src/helpers/config.ts @@ -1,3 +1,5 @@ +import mod from 'module' + import type { NetlifyConfig } from '@netlify/build/types' import destr from 'destr' import { readJSON, writeJSON } from 'fs-extra' @@ -164,6 +166,17 @@ export const configureHandlerFunctions = async ({ ) } + try { + // on Next 13.5+ there is no longer statically analyzable import to styled-jsx/style + // so lambda fails to bundle it. Next require hooks actually try to resolve it + // and fail if it is not bundled, so we forcefully add it to lambda. + + // eslint-disable-next-line n/no-unsupported-features/node-builtins + const nextRequire = mod.createRequire(require.resolve(`next`)) + const styledJsxPath = nextRequire.resolve(`styled-jsx/style`) + netlifyConfig.functions[functionName].included_files.push(styledJsxPath) + } catch {} + excludedModules.forEach((moduleName) => { const moduleRoot = resolveModuleRoot(moduleName) if (moduleRoot) {