I have used a regex to replace / to change it to a https:// path.
/
https://
const fileConents = `import { test } from "/some-path.js"` .replaceAll(/(^import [^"]+")\//gm, `$1${window.origin}/`);