crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.75k stars 182 forks source link

The emitted file "..." overwrites a previously emitted file of the same name #731

Closed thdoan closed 1 year ago

thdoan commented 1 year ago

Build tool

Vite

Where do you see the problem?

Describe the bug

When adding this to manifest.json:

  "web_accessible_resources": [
    {
      "matches": ["<all_urls>"],
      "resources": [
        "src/popup/popup.html"
      ]
    }
  ]

This error is displayed on build:

  VITE v4.3.9  ready in 1077 ms

  ➜  Local:   http://127.0.0.1:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help
The emitted file "src/popup/popup.html" overwrites a previously emitted file of the same name.

Reproduction

  1. Add the option above to manifest.json
  2. npm run build or vite

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 17.22 GB / 31.95 GB
  Binaries:
    Node: 16.20.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (114.0.1823.51)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @crxjs/vite-plugin: ^2.0.0-beta.17 => 2.0.0-beta.17
    vite: ^4.3.9 => 4.3.9

Severity

annoyance

jacksteamdev commented 1 year ago

If "src/popup/popup.html" is already in action.default_popup, Rollup emits this error.

I'm curious, what is your use case for web accessible HTML files?

thdoan commented 1 year ago

@jacksteamdev yeah I noticed that after removing "default_popup": "src/popup/popup.html" from the action key.

To make a long story short, I originally wanted to open the action popup from the context menu, but the Chrome team decided not to implement chrome.action.openPopup() in MV3 (for now):

https://bugs.chromium.org/p/chromium/issues/detail?id=1245093

I think when I submitted this ticket I was trying to render popup.html inside an iframe instead, which required me to add an entry in web_accessible_resources. Now that I know this works, I have removed "default_popup": "src/popup/popup.html" so this isn't an issue anymore.