bunchee icon indicating copy to clipboard operation
bunchee copied to clipboard

allow to disable esm shim?

Open himself65 opened this issue 1 year ago • 4 comments

https://github.com/huozhi/bunchee/blob/c4fd6184f30f8c6202141a6c249651fbc5d06aa2/src/build-config.ts#L278

himself65 avatar Mar 01 '24 22:03 himself65

There are some reasons, for example, there is a TS file that is

const fetch = globalThis.fetch === 'undefined' ? require('node-fetch') : fetch

I won't have node:module because this package might be published to the browser. I just want to do some environment check here

himself65 avatar Mar 02 '24 21:03 himself65

If you disable the esm shim then the bundled code will be incorrect? How the require is supposed to be handled.

I feel like you should just do polyfill on server side chunks or exports if that can solve your case.

huozhi avatar Mar 03 '24 22:03 huozhi

For example Im writing the polyfill code in a function it will both emit to cjs and esm. And in this case require function shouldn’t cause a side effect

himself65 avatar Mar 04 '24 04:03 himself65

It would cause other error if you don't shim require call, probably should consider dynamic import

huozhi avatar Mar 09 '24 20:03 huozhi