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

ES modules export doesn't work with rollup #10

Open
geoffreylitt opened this issue Jul 3, 2021 · 4 comments
Open

ES modules export doesn't work with rollup #10

geoffreylitt opened this issue Jul 3, 2021 · 4 comments

Comments

@geoffreylitt
Copy link

geoffreylitt commented Jul 3, 2021

I'm using ExtPay in a project that uses the rollup bundler. I got this error when running the bundler:

[!] Error: 'runtime' is not exported by node_modules/webextension-polyfill/dist/browser-polyfill.js, imported by node_modules/extpay/dist/ExtPay.module.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/extpay/dist/ExtPay.module.js (1:21)
1: import { management, runtime, storage, windows } from 'webextension-polyfill';

It appears that none of those four symbols are exported by the 'webextension-polyfill' module.

For the moment I was able to work around the issue by importing the commonjs version, which worked great.

I'm not sure if this is just some specific problem with my setup, or might be a broader issue with the module version of the package. It seems like webextension-polyfill might have an unusual module export format? From the readme:

Be aware that the polyfill module does not export the browser API object, but defines the browser object in the global namespace (i.e. window).
@Glench
Copy link
Owner

Glench commented Jul 4, 2021 via email

@geoffreylitt
Copy link
Author

It seems like the key issue is using the @rollup/plugin-node-resolve rollup plugin which uses the node resolution strategy. I don't yet fully understand when this plugin is needed, but I currently use it in my project and it seems like it's necessary to import certain npm packages.

I made a minimal test repository that uses this plugin in the rollup config, which should make it trivial to reproduce the issue I'm seeing. Details in the readme there:

https://github.com/geoffreylitt/extpay-test

@kylekampy
Copy link

kylekampy commented Mar 20, 2022

@geoffreylitt I ended up encountering this same issue due to having a similar setup. Could you share how you configured rollup to import the cjs version instead? Or did you just grab the .common.js version from dist instead of installing the npm module? Thanks :)

-- EDIT --
Stumbled into a solution myself. For anyone else, I added the rollup commonjs module (https://github.com/rollup/plugins/tree/master/packages/commonjs). This seemed to favor importing the .common.js. So my rollup config plugins are simply: plugins: [typescript(), nodeResolve(), commonjs()].

@geoffreylitt
Copy link
Author

geoffreylitt commented Mar 20, 2022 via email

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

No branches or pull requests

3 participants