Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"tinymce.init is not a function" when trying to browserify tinymce

I can't get a basic tinymce call to work in browserify, even though it works perfectly if I just load tinymce from a CDN. Here's a minimal example of what I'm trying to do.

// main.js
var tinymceConverter = require('./modules/tinymce-converter');

document.addEventListener('DOMContentLoaded', function () {
    tinymceConverter.init();
}

// tinymce-converter.js
'use strict';

var tinymce = require('tinymce/tinymce');

module.exports = {
    init: function () {
        tinymce.init({
            // some params
        });
    }
};

However, I get the Uncaught TypeError: tinymce.init is not a function error from the js console.

I have tried various combinations of other require calls, some in combination with jQuery, which is used a lot in this project. (Hence a solution with jQuery would be welcome, although my first priority is to get it working at all.) Am I missing something obvious?

like image 639
Joel Hinz Avatar asked Sep 17 '15 08:09

Joel Hinz


1 Answers

I got around it by adding setup attribute, then the console warned that I didn't have some plugins code and image, once I added those it stopped giving console errors and I was able to take out the setup attribute.

tinymce.init({ selector: '#tiny', plugins: ['paste', 'link', 'code', 'image'], setup: function(ed) { ed.on("init", function (ed) { alert(7); }) } });

like image 138
Adam Carnagey Avatar answered Nov 12 '22 19:11

Adam Carnagey