crxjs / chrome-extension-tools

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

Issue with rollup `simpleReloader` #815

Open DblK opened 1 year ago

DblK commented 1 year ago

Build tool

Rollup

Where do you see the problem?

Describe the bug

The background.js file is not loaded and crash once simpleReloader() is added to the configuration.

The error is Service worker registration failed. Status code: 3.

So I need to go back using manual refresh.

Reproduction

The source are private but here is my rollup configuration.

// rollup.config.js

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { obfuscator } from 'rollup-obfuscator';
import zip from 'rollup-plugin-zip';

import { chromeExtension, simpleReloader } from 'rollup-plugin-chrome-extension';

export default {
  input: 'src/manifest.json',
  output: {
    dir: 'dist',
    format: 'esm',
  },
  plugins: [
    // always put chromeExtension() before other plugins
    chromeExtension(),
    // simpleReloader(), // This is causing the issue
    resolve(),
    commonjs(),
    obfuscator(),
    zip({ dir: 'dist-zip' }),
  ],
};

Logs

This is the part which was highlighted :

  "background": {
    "service_worker": "background/background.js",
    "type": "module"
  },

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 129.56 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
  Browsers:
    Chrome: 118.0.5993.88
    Safari: 17.0
  npmPackages:
    rollup: ^4.1.4 => 4.1.4 
    rollup-plugin-chrome-extension: ^3.6.12 => 3.6.12

Severity

blocking all usage of RPCE

doniyor2109 commented 1 month ago

I had same issue and it seems reloader cannot properly import some assets.

Here is output structure:

dist/
    assets/
        background-page-reloader-25bf0b69.js
    background/
        index.js

However background/index.js is loading assets with wrong path

// SIMPLE RELOADER IMPORT
import "./assets/background-page-reloader-25bf0b69.js"