ionic-team / rollup-plugin-node-polyfills

MIT License
139 stars 59 forks source link

Using XMLHttpRequest causes an error when used in a ServiceWorker #31

Closed mattxyzeth closed 2 years ago

mattxyzeth commented 2 years ago

https://github.com/ionic-team/rollup-plugin-node-polyfills/blob/9b5fe1a9cafffd4871e6d65613ed224f807ea251/polyfills/http-lib/capability.js#L20

ServiceWorkers do not include the XMLHttpRequest object. This could be updated to use fetch instead to fix this issue.

mattxyzeth commented 2 years ago

I understand more about why this is used now. Is there any other way to perform these tests?

mattxyzeth commented 2 years ago

I'm going to close this because my issue was resolved by fixing the plugin position in the rollup config. Once I had that set properly the module that was causing issues was not imported in my service worker.

mattxyzeth commented 2 years ago

I should add the proper order for those finding this. In my case I was using this with the commonjs plugin. The proper order is to use commonjs, nodePolyfill, nodeResolve. The nodePolyfill should be before nodeResolve as stated in the examples.