|
1 |
| -import mod from 'module' |
2 |
| - |
3 | 1 | import type { NetlifyConfig } from '@netlify/build/types'
|
4 | 2 | import destr from 'destr'
|
5 | 3 | import { readJSON, writeJSON } from 'fs-extra'
|
@@ -75,9 +73,9 @@ export const updateRequiredServerFiles = async (publish: string, modifiedConfig:
|
75 | 73 | await writeJSON(configFile, modifiedConfig)
|
76 | 74 | }
|
77 | 75 |
|
78 |
| -export const resolveModuleRoot = (moduleName) => { |
| 76 | +export const resolveModuleRoot = (moduleName, paths = [process.cwd()]) => { |
79 | 77 | try {
|
80 |
| - return dirname(relative(process.cwd(), require.resolve(`${moduleName}/package.json`, { paths: [process.cwd()] }))) |
| 78 | + return dirname(relative(process.cwd(), require.resolve(`${moduleName}/package.json`, { paths }))) |
81 | 79 | } catch {
|
82 | 80 | return null
|
83 | 81 | }
|
@@ -164,18 +162,16 @@ export const configureHandlerFunctions = async ({
|
164 | 162 | `!${nextRoot}/dist/compiled/webpack/bundle4.js`,
|
165 | 163 | `!${nextRoot}/dist/compiled/webpack/bundle5.js`,
|
166 | 164 | )
|
167 |
| - } |
168 | 165 |
|
169 |
| - try { |
170 | 166 | // on Next 13.5+ there is no longer statically analyzable import to styled-jsx/style
|
171 | 167 | // so lambda fails to bundle it. Next require hooks actually try to resolve it
|
172 | 168 | // and fail if it is not bundled, so we forcefully add it to lambda.
|
173 |
| - |
174 |
| - // eslint-disable-next-line n/no-unsupported-features/node-builtins |
175 |
| - const nextRequire = mod.createRequire(require.resolve(`next`)) |
176 |
| - const styledJsxPath = nextRequire.resolve(`styled-jsx/style`) |
177 |
| - netlifyConfig.functions[functionName].included_files.push(styledJsxPath) |
178 |
| - } catch {} |
| 169 | + const styledJsxRoot = resolveModuleRoot('styled-jsx', [join(process.cwd(), nextRoot)]) |
| 170 | + if (styledJsxRoot) { |
| 171 | + const styledJsxStyleModulePath = join(styledJsxRoot, 'style.js') |
| 172 | + netlifyConfig.functions[functionName].included_files.push(styledJsxStyleModulePath) |
| 173 | + } |
| 174 | + } |
179 | 175 |
|
180 | 176 | excludedModules.forEach((moduleName) => {
|
181 | 177 | const moduleRoot = resolveModuleRoot(moduleName)
|
|
0 commit comments