vite-plugin-node-stdlib-browser icon indicating copy to clipboard operation
vite-plugin-node-stdlib-browser copied to clipboard

Incorrect import of main package

Open niksy opened this issue 2 years ago • 0 comments

There is a crucial difference in requiring main package inside .cjs file and using dynamic import as mentioned in official documentation.

If you use require, Vite treats every export from that file as CommonJS and adds heuristic which implements their own mocking implementation which is wrong in terms what node-stdlib-browser tries to achieve. Using dynamic import switches to ESM mode and uses ES modules implementatio which is a) correct in terms of mocking, b) allows tree-shaking and DCE.

Would you be willing to change that?

niksy avatar May 08 '23 08:05 niksy