-
Notifications
You must be signed in to change notification settings - Fork 25
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
Error in TypeScript + ESM setup #112
Comments
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
@Frando You should check out https://github.com/wd-David/esbuild-plugin-pino. Solved my issues for me. |
I tried looking into a way to make __dirname always available but it's not trivial, since ideally one should check the presence of "import.meta" and if it's there, then use the fileUrlToPath method to define __dirname. Unfortunately nodejs fails with an un-catcheable syntax error if you try to just "typeof import.meta" when you are in commonjs even in a code branch that's not supposed to run... Not sure how to do that. Luckily as @Frando pointed out - thanks to the good design one can override the 'thread-stream-worker' and everything works |
I would love for a better solution 😭. Each thread must have a different entry point. |
@mcollina can you please introduce pre-processor instructions to Nodejs? :D #ifdef ESM Done! ;) Seriously though, do you know why testing for the availability of "import.meta" generates an uncatchable error in node (it's a syntax error)? Tried in node 20... Anyway, there should also be a way to NOT use __dirname altogether here. |
This is my workaround 🙃 const dirname =
typeof __dirname !== 'undefined'
? __dirname
: fileURLToPath(new URL('.', import.meta.url)) I wish there was a better way... |
Hi,
I'm using thread-stream (through pino) in a project that uses TypeScript compiled to ESM modules, running in Node.js.
I'm getting this error when running the project:
I could fix the error through a hackish solution for the time being:
However, it would be nice if that could be fixed somehow upstream.
The text was updated successfully, but these errors were encountered: