首页 新闻 会员 周边

vscode extension 遇到奇怪的问题 "module is not defined"

0
悬赏园豆:30 [已解决问题] 解决于 2023-12-01 10:10

园子的 vsocode 扩展在 markdown 预览时浏览器控制台会报错 Uncaught ReferenceError: module is not defined,异常发生于 module.exports = e,详见下面的截图,截图中是 build 输出的 js 代码

对应的 markdown 预览定制代码实现见 markdown.entry.ts,请问如何解决这个问题?

dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2023-11-30 15:46

%userprofile%\.vscode\extensions\cnblogs.vscode-cnb-1.8.42-win32-x64\dist 中可以看到对应的 markdown.js 文件

dudu 4个月前

module.exports 是 CommonJS 中的

dudu 4个月前
< >
分享
最佳答案
0

检查一下 @cnblogs/markdown-it-presets相关的更新,试试回退或者锁一下到之前的版本试试

收获园豆:30
Laggage | 小虾三级 |园豆:878 | 2023-11-30 21:31

安装 v1.6.0 也有这个报错

dudu | 园豆:30994 (高人七级) | 2023-11-30 22:22

webpack打包的target有问题,提了个pr -> https://github.com/cnblogs/vscode-cnb/pull/258

Laggage | 园豆:878 (小虾三级) | 2023-11-30 23:39
其他回答(1)
0

通过 github 上的 issue What is commonjs2 ? 知道了 module.exports = ewebpack.config.mjs#L60 中的 libraryTarget: 'commonjs2' 引起的

CommonJs spec defines only exports. But module.exports is used by node.js and many other CommonJs implementations.

commonjs mean pure CommonJs
commonjs2 also includes the module.exports stuff.

dudu | 园豆:30994 (高人七级) | 2023-11-30 23:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册