我创建了一个基于https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite项目的扩展.
在 list I中,将background
类型设置为module
background: {
service_worker: "background.js",
type: "module",
},
在后台服务中,我动态创建页面内内容-脚本如下
await chrome.scripting.registerContentScripts([
{
id: currInpageId,
matches: ["file://*/*", "http://*/*", "https://*/*"],
js: [`inpage-${inpageType}.js`],
runAt: "document_start",
allFrames: true,
world: "MAIN",
},
]);
InPage文件作为单独的输入传递给vite.config
input: {
...inpageTypes.reduce(
(acc, inpageType) => ({
...acc,
[`inpage-${inpageType}`]: resolve(
inpageDir,
`inpage-${inpageType}.ts`
),
}),
{}
),
},
但是当我运行EXT时,我得到一个错误
未捕获语法错误:无法在模块外部使用导入语句
我怎么才能解决它呢?
谢谢!