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?