awesome-webextension / webpack-target-webextension

WebExtension Target for Webpack 5. Supports code-splitting and HMR.
MIT License
44 stars 5 forks source link

Conflict with HtmlWebpackPlugin - "Error: No chrome or browser runtime found" #35

Closed Juraj-Masiar closed 2 years ago

Juraj-Masiar commented 2 years ago

Hello, I'm trying to fix the dynamic imports in MV3 so I've added new WebExtension into the plugins array:

      new WebExtension({
        background: {
          entry: `background_gsd.worker`,
          // !! Add this to support manifest v3
          manifest: 3,
        },
      }),

And it seems to fix the background service worker, but at the same time my compilation now fails in the HtmlWebpackPlugin, which doesn't make sense to me:

ERROR in   Error: No chrome or browser runtime found

  - reload.html:81 Object.get runtime [as runtime]
    C:/Users/juraj/git/addons/GroupSpeedDial/src/reload/reload.html:81:92

  - reload.html:83
    C:/Users/juraj/git/addons/GroupSpeedDial/src/reload/reload.html:83:89

  - reload.html:84
    C:/Users/juraj/git/addons/GroupSpeedDial/src/reload/reload.html:84:13

  - reload.html:118
    C:/Users/juraj/git/addons/GroupSpeedDial/src/reload/reload.html:118:12

  - node:vm:139 Script.runInContext
    node:vm:139:12

  - index.js:142 HtmlWebpackPlugin.evaluateCompilationResult
    [GroupSpeedDial]/[html-webpack-plugin]/index.js:142:28

  - index.js:324
    [GroupSpeedDial]/[html-webpack-plugin]/index.js:324:26

  - async Promise.all

  - async Promise.all

Removing the new WebExtension(... from the plugins list fixes the problem so there must be some correlation I don't see. Can you help? Or do I need to provide some example project? Thanks!

Jack-Works commented 2 years ago

You need this: https://github.com/awesome-webextension/webpack-target-webextension#optionsweakruntimecheck

Juraj-Masiar commented 2 years ago

Thank you! It works now. I should have read the readme till the very end :)