AceEditor:未捕获错误:无法加载模块 ace/主题/

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

我在代码中使用 AceEditor。当我尝试保存更改时,出现此错误

Uncaught Error: couldn't load module ace/theme/ or it didn't call define
        at afterLoad (ace.js:18798:1)
        at ace.js:3776:1
        at Array.forEach (<anonymous>)
        at ace.js:3775:1
        at _require (ace.js:88:1)
        at req (ace.js:138:1)
        at afterLoad (ace.js:3771:1)
        at HTMLScriptElement.s.onload.s.onreadystatechange (ace.js:3397:1)

据我了解,要修复错误,我需要设置基本路径。但是,在 ace.tsx 文件中添加行

this.editor.set('basePath', 'https://unpkg.com/[email protected]/node-modules/react-ace/src')
没有帮助。

javascript reactjs ace-editor
3个回答
2
投票

basePath
是ace.js所在的文件夹。对于 unpkg 来说是

ace.config.set('basePath', "https://unpkg.com/[email protected]/src-noconflict")

请注意,该方法位于配置对象上,而不是编辑器实例上。

根据您使用的打包器,可能有更好的方法来配置它。


0
投票

从 'ace-builds' 导入 ace;

ace.config.set('basePath', 'https://unpkg.com/[电子邮件受保护]/src-noconflict');


0
投票

您需要将这些导入添加到文件顶部:

import 'ace-builds/src-noconflict/ext-language_tools';
import 'ace-builds/src-noconflict/mode-html'; // note `mode-HTML`; import the one you want to use
import 'ace-builds/src-noconflict/theme-terminal'; // note that `theme-TERMINAL` is the one i'm using; in your case you might need to import another
© www.soinside.com 2019 - 2024. All rights reserved.