使用monaco编辑器 报错Can only have one anonymous define call per script file

2022-07-28,,,,


问题描述:

打开monaco编辑器后,再打开含有amd加载方式的js文件时,报错 Can only have one anonymous define call per script file


原因分析:

这是因为monaco的资源文件中有个判断,不能一个项目中有两个define的定义函数,因为monaco需要自己的定义。所以避免define方法互相污染而报错,或者资源文件没加载!


解决方案:

在create之后 加上 

if(editor && "function" == typeof define && define.amd) {

    delete define.amd;

 }

虽然删掉了amd属性,对monaco也不会有影响。

我们看下下面webpack编译后的文件,这样再加载这个文件就不会走到define 的判断里面,所以不会再出现Can only have one anonymous define call per script file 这个报错

本文地址:https://blog.csdn.net/m0_38050352/article/details/109378179

《使用monaco编辑器 报错Can only have one anonymous define call per script file.doc》

下载本文的Word格式文档,以方便收藏与打印。