Glench / ExtPay

The JavaScript library for ExtensionPay.com — payments for your browser extensions, no server needed.
https://extensionpay.com
Other
524 stars 66 forks source link

Extpay simply doesn't work with a bundler.. #207

Closed midwid closed 6 months ago

midwid commented 6 months ago

I'm struggling for days now with this issue,

I'm building an extension using : "esbuild": "^0.20.0"

I just cannot import extpay, It just doesn't work.

I did npm install extpay and then the code bevlow in my service worker.

import ExtPay from "../node_modules/extpay/dist/ExtPay.module.js"; var extpay = ExtPay('sample-extension'); extpay.startBackground();

But the first bug was that it couldn't find the module pollyfill...

Service worker ERROR : Uncaught TypeError: Failed to resolve module specifier "webextension-polyfill". Relative references must start with either "/", "./", or "../".

So I had to dig in the Extpay.module.js to write the path like so :

import { management, runtime, storage, windows } from '../../webextension-polyfill/dist/browser-polyfill.js';

but now, there's a new problem.. There's no 'management' export in the polyfill module..

Service worker ERROR : Uncaught SyntaxError: The requested module '../../webextension-polyfill/dist/browser-polyfill.js' does not provide an export named 'management'

I'm pretty lost at this point guys, if I have to modify the modules myself...seems like nothing I can do..

Expected behavior I just want the ExtPay module to work 🥲

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

I also tested the sampleMV3 extension to verify if it's not a problem from my hardware, but it works fine.

Glench commented 6 months ago

Hi @midwid! Looks like you might have misconfigured your webpack! I would not use relative paths or import from node_modules. Just do the standard import ExtPay from extpay. If you still cannot get it working, please create a minimal repository demonstrating the issue and link it here! I'm closing the issue now and will re-open if you can reproduce it.