Description
Description
There is a stray call to require
in what is otherwise a perfectly good ES module here:
ipywidgets/packages/controls/src/index.ts
Line 27 in 52663ac
When this is published to NPM, it is transpiled from TypeScript but not bundled. So the production source looks the same: an ES module with a random require
at the bottom. See here in lib/index.js
.
If I try to bundle this package using Rollup into a library targeting ESM, and then use it in a web browser, that require remains there and causes a crash, because require
doesn't exist in browsers. I'm doing this via Vite, which uses Rollup to compile for production.
There may be some advanced options for Rollup which will cause it to properly transform the require in a "mixed ES module" like this, which could serve as a workaround. But I think it would be more sensible to just remove the require. It seems its only purpose is to import the version string from package.json
. I bet there's a way to insert it directly during the build process instead.