andywer / andywer/threads.js

Avoid use of `eval` in worker_threads.ts?

Abierto
#382 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
3.5k
Forks
173
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.