Skip to content

ESM builds should substitute __filename and __dirname references in CommonJS #14072

@guybedford

Description

@guybedford

Feature request

What is the expected behavior?

When building an ESM build in Webpack, free __filename and __dirname references in CommonJS files should be supported.

What is motivation or use case for adding/changing the behavior?

See eg vercel/ncc#749 for an ncc bug here.

How should this be implemented in your opinion?

The referencing could do relative path logic or not. That shoudl likely be configurable. In the base case for CommonJS the __filename value would be the output file __filename value which seemed to work in some scenarios.

One could just define CJS free __filename references as fileURLToPath(import.meta.url) in the Webpack bundle.

Are you willing to work on this yourself?
no

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions