Chrome 扩展:未捕获语法错误:无法在模块外部使用 import 语句

问题描述 投票:0回答:1

这里有很多类似的线程,但我似乎找不到任何适合我的东西。我正在构建一个 chrome 扩展,我想在其中连接到 websocket。我找到了一个项目,https://github.com/matthewlawson/lnm-socket.io,我尝试将其用作灵感,尽管我无法让它为我工作。

服务器不在 chrome 扩展中,但我尝试从我的 background.js 文件访问它。就在那时,我收到了 Cannot use import statements Outside a module 错误消息。将 "type": "module" 添加到我的 package.json 文件似乎无法修复它,并且由于它是后台文件,我没有将它放在脚本标记中来放置 "type": "module" 。什么我可以做什么吗?

node.js syntax-error chrome-extension-manifest-v3
1个回答
0
投票

我找到的解决方案是不更改manifest.json;相反,这就是 javascript 文件的加载方式。

我从

<script src="/dist/popup.js"></script>

<script type="module" src="/dist/popup.js"></script>

© www.soinside.com 2019 - 2024. All rights reserved.