Skip to content

fix: resolve symlinked npm global bin path for standalone server.js#17

Merged
NiveditJain merged 1 commit into
mainfrom
ef-17
Apr 7, 2026
Merged

fix: resolve symlinked npm global bin path for standalone server.js#17
NiveditJain merged 1 commit into
mainfrom
ef-17

Conversation

@NiveditJain

@NiveditJain NiveditJain commented Apr 6, 2026

Copy link
Copy Markdown
Member

Summary

  • When failproofai is installed globally via npm and run, bun can resolve import.meta.url to the symlink's directory (e.g. ~/.npm-global/bin/) rather than the real package directory, so the .next/standalone/server.js path gets computed as ~/.next/standalone/server.js (missing the lib/node_modules/failproofai portion)
  • Fix: wrap fileURLToPath(import.meta.url) with realpathSync in both scripts/launch.ts and bin/failproofai.mjs so symlinks are always resolved before path arithmetic
  • Belt-and-suspenders: bin/failproofai.mjs sets FAILPROOFAI_PACKAGE_ROOT early (before any dynamic imports) so launch.ts can use it as a primary source

Test plan

  • npm pack the package and install it globally: npm install -g ./failproofai-*.tgz
  • Run failproofai from ~ — dashboard should start on port 8020 without the Cannot find module error
  • Run bun run test:run — existing tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved application startup reliability by enhancing how required files are located, ensuring consistent functionality across different installation environments and system configurations.

When failproofai is installed globally via npm, the bin entry is a
symlink. Bun can resolve import.meta.url to the symlink's directory
rather than the real package directory, causing server.js to be
looked up at the wrong path (e.g. ~/.next/standalone/server.js).

Fix by wrapping fileURLToPath with realpathSync in both the bin entry
point and scripts/launch.ts. The bin script also sets
FAILPROOFAI_PACKAGE_ROOT early (before any dynamic imports) so
launch.ts has a reliable fallback even if its own import.meta.url
resolution is affected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 1d3e49dd-d61d-4120-810c-f7dcc430c1ad

📥 Commits

Reviewing files that changed from the base of the PR and between ca824cc and e1a9bad.

📒 Files selected for processing (2)
  • bin/failproofai.mjs
  • scripts/launch.ts

📝 Walkthrough

Walkthrough

The changes establish a more reliable package root resolution mechanism. The bin/failproofai.mjs script now initializes process.env.FAILPROOFAI_PACKAGE_ROOT early by resolving the real filesystem path and following npm bin symlinks. The scripts/launch.ts then uses this environment variable to locate the Next.js standalone server, replacing the previous direct path calculation.

Changes

Cohort / File(s) Summary
Package Root Initialization
bin/failproofai.mjs
Added Node.js path/URL imports and early initialization of process.env.FAILPROOFAI_PACKAGE_ROOT by resolving the real filesystem path of the script, ensuring it persists to downstream code.
Path Resolution Update
scripts/launch.ts
Updated the start mode command argument resolution to use the environment-variable-backed packageRoot instead of direct import.meta.url path calculation, improving reliability across varying module resolution behaviors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A symlink once posed a puzzle so deep,
But now our brave roots are secure and they keep,
FAILPROOFAI_PACKAGE_ROOT stands tall and true,
Following paths through npm's forest anew! 🌲✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@NiveditJain NiveditJain merged commit a145872 into main Apr 7, 2026
8 checks passed
@NiveditJain NiveditJain deleted the ef-17 branch April 21, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant