Search code examples
javascriptreactjsace-editor

AceEditor:Uncaught Error: couldn't load module ace/theme/


I use AceEditor in my code. When I try to save my changes, I get this error

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)

As I understand it, to fix the error, i need to set basepath.However, adding the line this.editor.set('basePath', 'https://unpkg.com/[email protected]/node-modules/react-ace/src') in the ace.tsx file does not help.


Solution

  • The basePath is the folder where ace.js is located. for unpkg it would be

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

    note that the method is on config object not on editor instance.

    Depending on what packager you use there may be better ways to configure this.