andywer / andywer/threads.js

Avoid use of `eval` in worker_threads.ts?

Ouverte
#382 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
3.5k
Forks
173
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

https://github.com/andywer/threads.js/blob/42b1042f9a0057fd25c94807ba4ac988e6475916/src/worker_threads.ts#L20

Thanks for all your work on `threads.js`! I am working with `rollup` and running into an issue due to the use of `eval("require")("worker_threads")` when creating an ESM output. Rollup cannot convert the `eval("require")` to a top-level import statement `import require$$0 from 'worker_threads'` since it doesn't not recognize it statically as a commonjs `require("worker_threads")`.

This means that in the final ESM bundle ends up with a `eval("require")` which throws at runtime since require is not allowed when using ESM in node. I see the comment "Webpack hack" and am curious if the use of eval is a part of that hack? Or would there be an option to avoid the use of `eval` and change this to `require("worker_threads")`? Cheers!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.