Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@jupyter-widgets/controls: require() call breaks ES module #3854

Open
thomasjm opened this issue Oct 23, 2023 · 0 comments · May be fixed by #3855
Open

@jupyter-widgets/controls: require() call breaks ES module #3854

thomasjm opened this issue Oct 23, 2023 · 0 comments · May be fixed by #3855

Comments

@thomasjm
Copy link

thomasjm commented Oct 23, 2023

Description

There is a stray call to require in what is otherwise a perfectly good ES module here:

export const version = (require('../package.json') as any).version;

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.

@thomasjm thomasjm linked a pull request Oct 23, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant