Skip to content

fix: resolve package.json from the function's directory in detectZisiBuilder - #8424

Open
bsplatt92 wants to merge 1 commit into
netlify:mainfrom
bsplatt92:fix/zisi-read-package-up
Open

fix: resolve package.json from the function's directory in detectZisiBuilder#8424
bsplatt92 wants to merge 1 commit into
netlify:mainfrom
bsplatt92:fix/zisi-read-package-up

Conversation

@bsplatt92

Copy link
Copy Markdown

Summary

Fixes #8423.

detectZisiBuilder passed func.mainFile (a string) to readPackageUp, but read-package-up expects an options object ({ cwd }). The string was silently ignored and the package.json lookup fell back to process.cwd() — the pre-existing @ts-expect-error TODO on that line ("We seem to be incorrectly using this function, but it seems to work... Investigate.") was flagging exactly this.

When netlify dev runs with --cwd <project> from a directory outside the project (the CLI honors --cwd for config resolution but never process.chdir()s), no package.json is found, hasTypeModule is incorrectly false, and the {"type":"commonjs"} marker is never written into the functions-serve directories. In a project whose root package.json has "type": "module", every zisi/esbuild CJS function bundle is then parsed as ESM and every function invocation 500s with ReferenceError: module is not defined in ES module scope.

This resolves the lookup from the function's own directory instead, which is exactly what @netlify/functions-dev already does in its equivalent code path (readPackageUp({ cwd: path.dirname(func.mainFile) })), and lets the @ts-expect-error be dropped.

Testing

  • npm run typecheck passes (the @ts-expect-error removal confirms the call now matches the library's types).
  • Manually verified against a real project (root package.json with "type": "module", v1 .ts function, node_bundler = "esbuild"): running netlify dev --cwd <repo> from an outside directory previously 500'd every function with module is not defined in ES module scope; with this change the {"type":"commonjs"} marker is written into each .netlify/functions-serve/<name>/ directory and all functions respond normally. Running from inside the repo is unaffected.

There are currently no unit tests covering detectZisiBuilder — happy to add one if you can point me at the preferred harness for this module.

🤖 Generated with Claude Code

…Builder

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 netlify#8423

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bsplatt92
bsplatt92 requested a review from a team as a code owner August 17, 2026 22:46
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: af6324ca-bc37-4104-a3c3-431a3e08e819

📥 Commits

Reviewing files that changed from the base of the PR and between 68938dd and 6e1fbad.

📒 Files selected for processing (1)
  • src/lib/functions/runtimes/js/builders/zisi.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • netlify/blueprints (manual)

Included review availability: Your plan includes up to 4 reviews per rolling hour; 3 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved JavaScript runtime detection by correctly locating package information relative to each function’s main file.
    • Removed an internal compatibility workaround for more reliable build behavior.

Walkthrough

detectZisiBuilder now calls readPackageUp with an options object containing the directory of func.mainFile. The change removes the TypeScript suppression and ensures package metadata is resolved from the function directory.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 6e1fb

This localized fix resolves package.json from the function directory so CommonJS function bundles are marked correctly when running from outside the project; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: eduardoboucas

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: resolving package.json from the function directory.
Description check ✅ Passed The description directly explains the bug, the fix, the affected runtime behavior, and the verification performed.
Linked Issues check ✅ Passed The change implements the suggested fix for #8423 and addresses package lookup, module detection, CommonJS markers, and invocation failures.
Out of Scope Changes check ✅ Passed The pull request contains only the targeted readPackageUp fix and removal of its related TypeScript suppression.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant