Search code examples
javascriptrequirejsace-editor

Unable to use Ace as RequireJS dependency


I'm trying to use Ace with RequireJS, but this code below is not working. The Ace script was downloaded, but the required parameter ace is always undefined.

requirejs(['https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.3/ace.js'], function (ace /*always undefined*/) {
  console.log(ace);
});

I'm using RequireJS 2.3.6

Screenshot from 2019-03-24 16-26-55


Solution

  • It seems that, in order to work, you need to configure a path in requirejs configuration pointing to the CDN folder:

    requirejs.config({
        baseUrl: '',
        paths: {
            ace: ['https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.3/']
        }
    });
    

    and then require the ace module:

    requirejs(['ace/ace'], function (ace) {
        console.log(ace);
    });