Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails / Webpack: TinyMCE cannot load skins (404 (Not Found))

I am working on a Rails project that has been using assets pipeline but we are currently trying to transition to webpack. I encountered a problem when attempting to get TinyMCE to work after pulling it through yarn - the text editor simply won't load.

Before the transition to webpack

Originally I used a CDN in the application.html.haml and things were working fine:

%script{src: 'https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=gexncjni90zx3qf0m5rr7kl8l40wd5yuly2xjza0g3kwrljt'}`

After the transition

I installed the package through yarn: $ yarn add tinymce

I also have my tinyMce.js file (the function itself has not been changed):

import tinymce from 'tinymce/tinymce';
import 'tinymce/themes/modern/theme';
import 'tinymce/plugins/lists';
import 'tinymce/plugins/table';

function tinyMce() {
    $(document).on('turbolinks:load', function () {
        tinyMCE.remove();
        tinyMCE.init({
            selector: 'textarea.tinymce',
            plugins: [
                'table', 'lists'
            ],
        });
    });
}

export { tinyMce };

And in my application.js:

import { tinyMce } from "../vendor/tinyMCE/tinyMce";

Since TinyMCE will not work without a skin, I followed the documentation and ran

$ cp -r node_modules/tinymce/skins skins

But the error in the console does not get resolved: enter image description here

I tried putting the skins folder directly in the root directory, in a packs folder placed in the root and in the javascript/packs but the error stays the same, even when I try specifying the skin_url.

General notes

  • Webpack itself is working fine, both with custom scripts and imported packs (tested with typed.js).
  • tinymce seems to be loading as well - previously I had more errors in the console, regarding the table and lists plugins, but these went away after adding the 2 import lines to tinyMce.js.

Any tips on what I might be missing?

like image 604
Joanna Gaudyn Avatar asked Sep 12 '18 15:09

Joanna Gaudyn


1 Answers

I managed to get it to work by adding these 2 lines to my tinyMce.js file:

import 'tinymce/skins/lightgray/content.min.css';
import 'tinymce/skins/lightgray/skin.min.css';

At that point the text editor was working as expected, however I was getting the following errors in my console:

enter image description here

This was resolved by adding skin: false to my tinymce.initsetup.

like image 183
Joanna Gaudyn Avatar answered Oct 15 '22 04:10

Joanna Gaudyn