1

I am making a chrome extension using manifest v3.

I am trying to import my script files into the background.js.

I am using the second method described here

I have thus this in manifest.json:

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

On a simple script with no other dependency:

in myscript.js:

export function myFunction() {
  console.log("In myFunction!")
}

and in my background.js :

import { myFunction } from "./lib/myscript.js";

myFunction()

In that simple case, it works fine.

However, if I try to add another dependency in myscript.js from myscript2.js, like this:

myscript2.js:

export function mySecondFunction() {
  console.log("In mySecondFunction!")
}

and myscript.js (same directory as myscript2):

import { mySecondFunction} from "./myscript2.js";

export function myFunction() {
  console.log("In myFunction!")
  mySecondFunction()
}

In that case, it doesn't work anymore and I get the error "Service worker registration failed".

What should I be doing to fix this issue?

Gatsu
  • 11
  • 1
  • 3
  • Sounds like all paths are relative to the main script background.js so the second one should have `/lib/` too. If this will work, you can open a new bug report on https://crbug.com. – wOxxOm Aug 06 '21 at 10:14
  • Thank you, that solved my issue – Gatsu Aug 06 '21 at 11:44

0 Answers0