Skip to content

Conversation

@WonderSTK
Copy link

This commit fixes an issue where __dirname and __filename were not being correctly resolved in CommonJS modules when using Turbopack. The issue was that the origin of the requiring module was being used to resolve these variables, instead of the origin of the CJS module itself.

To fix this, I've introduced a new CjsPath variant to the FreeVarReference enum. This new variant is used to represent __dirname and __filename in CJS modules. The handle_free_var_reference function in urbopack/crates/turbopack-ecmascript/src/references/mod.rs has been updated to handle this new variant and resolve the path correctly using the origin of the CJS module.

This change ensures that __dirname and __filename have the correct values in CJS modules, which is important for compatibility with existing Node.js code.

Fixes #86476

This commit fixes an issue where __dirname and __filename were not being correctly resolved in CommonJS modules when using Turbopack. The issue was that the origin of the requiring module was being used to resolve these variables, instead of the origin of the CJS module itself.

To fix this, I've introduced a new CjsPath variant to the FreeVarReference enum. This new variant is used to represent __dirname and __filename in CJS modules. The handle_free_var_reference function in 	urbopack/crates/turbopack-ecmascript/src/references/mod.rs has been updated to handle this new variant and resolve the path correctly using the origin of the CJS module.

This change ensures that __dirname and __filename have the correct values in CJS modules, which is important for compatibility with existing Node.js code.

Fixes vercel#86476
@ijjk ijjk added the Turbopack Related to Turbopack with Next.js. label Nov 24, 2025
@ijjk
Copy link
Member

ijjk commented Nov 24, 2025

Allow CI Workflow Run

  • approve CI run for commit: 9ce6a59

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

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

Labels

Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

__dirname is /ROOT/... instead of real path in Turbopack

2 participants