fix: use require.resolve() for exec-child.js path to fix Next.js/webp… by CodeAurelius0 · Pull Request #1259 · shelljs/shelljs · GitHub
Skip to content

fix: use require.resolve() for exec-child.js path to fix Next.js/webp…#1259

Open
CodeAurelius0 wants to merge 1 commit into
shelljs:mainfrom
CodeAurelius0:main
Open

fix: use require.resolve() for exec-child.js path to fix Next.js/webp…#1259
CodeAurelius0 wants to merge 1 commit into
shelljs:mainfrom
CodeAurelius0:main

Conversation

@CodeAurelius0

Copy link
Copy Markdown

…ack bundler compatibility (#1158)

When Next.js (or any webpack-based bundler) bundles the server-side code, __dirname is replaced with the bundled output directory (e.g. .next/server/vendor-chunks/). This causes child_process.execFileSync to look for exec-child.js in the wrong location, leading to the 'Cannot find module' error.

Fix: resolve exec-child.js path using require.resolve() at module load time. require.resolve() always returns the real filesystem path of the module, unaffected by bundler __dirname transformations.

…ack bundler compatibility (shelljs#1158)

When Next.js (or any webpack-based bundler) bundles the server-side code,
__dirname is replaced with the bundled output directory (e.g. .next/server/vendor-chunks/).
This causes child_process.execFileSync to look for exec-child.js in the wrong location,
leading to the 'Cannot find module' error.

Fix: resolve exec-child.js path using require.resolve() at module load time.
require.resolve() always returns the real filesystem path of the module,
unaffected by bundler __dirname transformations.
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