javascript - 如何将 javascript 模块导入 Firefox WebExtension 后台脚本
问题描述
这是我的清单:
"background": {
"page": "./src/background_scripts/background.html"
},
这是我的背景.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script type="module" src="./ScrapingContent.js"></script>
</body>
</html>
这是 ScrapingContent.js:
import * as cheerio from "../../node_modules/cheerio/index.js"
但我得到了错误:
ReferenceError: require is not defined
现在显然我还需要导入 require,所以我将我的 background.html 更改为:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script type="text/javascript"src="../../node_modules/requirejs/require.js"></script>
<script type="module" src="./ScrapingContent.js"></script>
</body>
</html>
我得到了错误:
Error: Module name "lib/static" has not been loaded yet for context: _. Use require([])
https://requirejs.org/docs/errors.html#notloaded
如何导入这些模块/外部库?
解决方案
推荐阅读
- java - 自定义 JNI 方法链接器或在 Java 应用程序中注册
- java - 初始化 StandardFileSystemManager 的最佳实践是什么
- c++ - 令人不安的评价顺序
- php - 将用户名保存在变量/函数中以备后用
- angular - rxjs switchMap 类型不匹配问题
- linux - GStreamer:具有不会构建的依赖项的插件
- php - 简码中的编辑按钮重定向到数据库 Wordpress 中的项目页面
- python - 如何将 matplotlib 3d 绘图更改为侧视图?
- python - date_parser 和 read_csv 的功能不起作用
- wpf - 中文/Bopomofo 未在 wpf 中的绑定文本属性上触发 PropertyChanged