Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace import.meta.url, _filename, and _dirname appropriately #42

Closed
knightedcodemonkey opened this issue May 24, 2024 · 1 comment · Fixed by #44
Closed

Replace import.meta.url, _filename, and _dirname appropriately #42

knightedcodemonkey opened this issue May 24, 2024 · 1 comment · Fixed by #44
Labels
bug Something isn't working

Comments

@knightedcodemonkey
Copy link
Owner

When the dual build is CJS

  • Replace import.meta.url with something like require('url').pathToFileURL(__filename).toString().

When the dual build is ESM

  • Repalce __filename with import.meta.filename or fileURLToPath(import.meta.url). The latter option allows supporting older node versions.
  • Replace __dirname with import.meta.dirname or dirname(fileURLToPath(import.meta.url)).

https://nodejs.org/api/esm.html#no-__filename-or-__dirname

@knightedcodemonkey knightedcodemonkey added the bug Something isn't working label May 24, 2024
@knightedcodemonkey
Copy link
Owner Author

Interesting tsc behavior filed in TypeScript/58658.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant