From 6e1fbad40b7897381e4d22792273dffa56212bf0 Mon Sep 17 00:00:00 2001 From: Ben Splatt Date: Tue, 18 Aug 2026 08:45:57 +1000 Subject: [PATCH] fix: resolve package.json from the function's directory in detectZisiBuilder readPackageUp expects an options object, so passing func.mainFile as a string was silently ignored and the lookup fell back to process.cwd(). When netlify dev runs with --cwd from outside the project, no package.json is found, hasTypeModule is wrongly false, and the {"type":"commonjs"} marker is never written into the functions-serve directories - in a "type": "module" project every CJS function bundle is then parsed as ESM and 500s with "module is not defined in ES module scope". Resolve from the function's directory instead, matching @netlify/functions-dev. Fixes #8423 Co-Authored-By: Claude Fable 5 --- src/lib/functions/runtimes/js/builders/zisi.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/functions/runtimes/js/builders/zisi.ts b/src/lib/functions/runtimes/js/builders/zisi.ts index 83d471f37db..54d9d9d518a 100644 --- a/src/lib/functions/runtimes/js/builders/zisi.ts +++ b/src/lib/functions/runtimes/js/builders/zisi.ts @@ -186,8 +186,7 @@ export default async function detectZisiBuilder({ }) { const functionsConfig = netlifyConfigToZisiConfig({ config, projectRoot }) - // @ts-expect-error(serhalp) -- We seem to be incorrectly using this function, but it seems to work... Investigate. - const packageJson = await readPackageUp(func.mainFile) + const packageJson = await readPackageUp({ cwd: path.dirname(func.mainFile) }) const hasTypeModule = packageJson?.packageJson.type === 'module' const featureFlags: FeatureFlags = {}