Skip to content

Commit

Permalink
fix: styled-jsx solution for 13.5
Browse files Browse the repository at this point in the history
  • Loading branch information
taty2010 committed Oct 6, 2023
1 parent 730fb3e commit 0ae9034
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/runtime/src/helpers/config.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0ae9034

Please sign in to comment.