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

[BUG] Regression in bgsw on Firefox: Could not resolve bundle with id X #628

Closed
2 of 3 tasks
GarciaLnk opened this issue Jun 10, 2023 · 17 comments · Fixed by #632
Closed
2 of 3 tasks

[BUG] Regression in bgsw on Firefox: Could not resolve bundle with id X #628

GarciaLnk opened this issue Jun 10, 2023 · 17 comments · Fixed by #632
Labels
bug Something isn't working

Comments

@GarciaLnk
Copy link

What happened?

I'm working with the following library in the background service worker of my extension: https://github.com/visheratin/web-ai

In Plasmo 0.74.2 everything worked fine on every browser (Firefox and Chromium-based), however after updating to Plasmo 0.75.2, I get an error on Firefox. It's worth noting that everything still works fine on Chromium-based browsers, and if I try to use the library in the popup, the error disappears.

This is the minimal reproducible example of the background.ts that triggers the error in 0.75.2:

import { TextModel } from "@visheratin/web-ai";

async function initializeModel() {
    const result = await TextModel.create("mini-lm-v2-quant");
    console.log(result.elapsed);
}

initializeModel().catch(console.error);

I suspect this is yet another error related to Parcel.

Version

Latest

What OS are you seeing the problem on?

Linux

What browsers are you seeing the problem on?

Firefox

Relevant log output

23:22:07.590 Error: Could not resolve bundle with id 10tWj
    resolve1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:23108
    jDl6D moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:23037
    newRequire1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:29
    localRequire1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:34
    createSession1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:1072
    init moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:23781
    create moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:187
    initializeModel1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:93
    bkg1o moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:96
    newRequire1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:29
    localRequire1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:34
    frrV4 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:83
    newRequire1 moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:29
    <anonymous> moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:66
    <anonymous> moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:80
    <anonymous> moz-extension://f7479e89-e56d-4396-ae2b-78503febcb6d/background.a5c7ae1c.js:51360

(OPTIONAL) Contribution

  • I would like to fix this BUG via a PR

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.
@GarciaLnk GarciaLnk added the bug Something isn't working label Jun 10, 2023
@louisgv
Copy link
Contributor

louisgv commented Jun 10, 2023

It works on Chrome but not FF??? This is very weird because if you look at the diff between 0.74 -> 0.75, there's no change in the FF codepath. The last change to FF bundling happened in 0.74! xD...

v0.74.2...v0.75.2

It is possible that Parcel upgrade might have introduced some weird stuff, however the fact that it works in Chrome but not FF shows it might not be the bundler but something else...

@louisgv
Copy link
Contributor

louisgv commented Jun 10, 2023

@GarciaLnk would you mind creating a sample repro repo that I can clone and play around with

@GarciaLnk
Copy link
Author

@GarciaLnk would you mind creating a sample repro repo that I can clone and play around with

Sure, here it is: https://github.com/GarciaLnk/sample-plasmo-bug

@louisgv louisgv linked a pull request Jun 13, 2023 that will close this issue
3 tasks
@louisgv
Copy link
Contributor

louisgv commented Jun 13, 2023

@GarciaLnk should be fixed in latest patch

@GarciaLnk
Copy link
Author

Hm, I'm still getting the same "Could not resolve bundle" error after updating to v0.75.3.

@louisgv do you not get any errors in the background script of the sample repo with the new patch?

@louisgv louisgv reopened this Jun 13, 2023
@louisgv
Copy link
Contributor

louisgv commented Jun 13, 2023

@GarciaLnk just re-tested again, you're right. The bundle stripped some module with es2022 minifier target. I updated it to es2022 in v0.76.0, should work now.

@louisgv louisgv closed this as completed Jun 13, 2023
@GarciaLnk
Copy link
Author

I think things have gotten a bit weirder with v0.76.0, now when I try the sample repo apparently no error is triggered, but also the background service doesn't seem to work (?), neither the console.log() before nor after the call to the function appear in DevTools.

And if I try to build it with the --no-minify flag, the behavior is the same as before, the "Could not resolve bundle" error appears again.

For reference, this is how the console should look like in a successful execution of the bg service in the sample repo:
image

@louisgv louisgv reopened this Jun 13, 2023
@louisgv
Copy link
Contributor

louisgv commented Jun 13, 2023

It's kinda baffling that it works in dev mode but in prod mode even with minify turned off, it breaks???... I'm not entirely sure what the heck's going on lol bc dev mode and prod mode are not that diff with minify off...

@louisgv
Copy link
Contributor

louisgv commented Jun 14, 2023

@GarciaLnk hmm.. it doesn't work on Chrome for me in 0.74.x either:

Screenshot 2023-06-13 at 7 41 14 PM

BGSW cannot spawn worker in chrome, you will need to use #527 instead

@louisgv
Copy link
Contributor

louisgv commented Jun 14, 2023

@GarciaLnk Found a fix to force single bundle to be produced. At least it works for me in Firefox, tho for chrome it's not possible to use web API in BGSW (since it's a SW runtime instead of page runtime like FF) xd

@louisgv louisgv closed this as completed Jun 14, 2023
@GarciaLnk
Copy link
Author

GarciaLnk commented Jun 14, 2023

@GarciaLnk hmm.. it doesn't work on Chrome for me in 0.74.x either:
Screenshot 2023-06-13 at 7 41 14 PM

BGSW cannot spawn worker in chrome, you will need to use #527 instead

That was not related to this issue, I just forgot to make the sample repo Chrome-compatible 😅

By default, the library spawns multiple workers to enable multithreading processing, but this can be worked around for Chrome's MV3 switching to single thread execution (with SessionParams.numThreads = 1), which is what I do on my extension.

Anyways, v0.76.1 does seem to fix the issue on Firefox, however now I don't know how to access web-accessible resources on Chrome from the background service, since it now expects them to be at /static/background and not at the root of the extension (somehow this doesn't seem to be a problem on Firefox?). I'm not sure whether this can be solved with a simple workaround, or I should open a new issue.

@louisgv
Copy link
Contributor

louisgv commented Jun 14, 2023

Anyways, v0.76.1 does seem to fix the issue on Firefox, however now I don't know how to access web-accessible resources on Chrome from the background service, since it now expects them to be at /static/background and not at the root of the extension (somehow this doesn't seem to be a problem on Firefox?). I'm not sure whether this can be solved with a simple workaround, or I should open a new issue.

Can you ping me the exact issue you're seeing? If you use the url: scheme for your WARs, they should point at root just as normal. Only the BGSW itself is thrown under /static/background

Also a new issue would be great yeah - I just link issue to PR and they autoclose as a result of merging :p...

@GarciaLnk
Copy link
Author

@louisgv this bug is back with v0.76.2

@louisgv
Copy link
Contributor

louisgv commented Jun 16, 2023

Whoops my bad @GarciaLnk - can you try v0.76.3

@GarciaLnk
Copy link
Author

Whoops my bad @GarciaLnk - can you try v0.76.3

Fixed, kudos

@andrasbacsai
Copy link

I still have the issue with v0.77.5, and not just in Firefox, but in Chrome& Edge as well.

@louisgv
Copy link
Contributor

louisgv commented Jul 3, 2023

@andrasbacsai can you open a new issue with a minimal reprod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants