react-froala-wysiwyg icon indicating copy to clipboard operation
react-froala-wysiwyg copied to clipboard

Element is not defined error while importing plugins js file

Open gondar00 opened this issue 6 years ago • 8 comments

When i try to import the plugins js file froala-editor/js/plugins.pkgd.min.js i get the error as shown in the attached screenshot

image

I am using nextjs with ssr

gondar00 avatar Jun 13 '19 11:06 gondar00

This happens because Element is a web API which isn't available on Node.js.

As described in https://github.com/froala/react-froala-wysiwyg/issues/89, you can use Next.js's dynamic helper to execute the module only in the browser:

const FroalaEditor = dynamic(() => import('react-froala-wysiwyg'), {
  ssr: false
});

elliottsj avatar Jun 30 '19 20:06 elliottsj

@elliottsj the error is being thrown from the plugins file froala-editor/js/plugins.pkgd.min.js

gondar00 avatar Jul 03 '19 05:07 gondar00

Dynamically importing the plugins file do not load the plugins (image etc) on the editor

gondar00 avatar Jul 03 '19 05:07 gondar00

I am experiencing this issue as well. Were you able to get past this @gondar00 ?

FaithAdekunle avatar Jan 29 '20 14:01 FaithAdekunle

Hi. I am facing this issue. Does anybody know how to solve this?

dln88 avatar May 18 '20 07:05 dln88

Please resolve or mention a soultion.

karthik-js avatar Aug 26 '20 06:08 karthik-js

Getting this error, any help? I'm assuming it's because it can't find the editor when the plugin is imported??

EDIT: I was correct. As you used a dynamic helper to import Froala, you'll need to do the same when importing the plugin eg: const Lists = dynamic(import("froala-editor/js/plugins/lists.min.js"));

helencheunggg avatar Apr 01 '21 16:04 helencheunggg

Define your editor component in a separate module and import that one dynamically:

// components/MyFroalaEditor.tsx

import 'froala-editor/js/plugins.pkgd';
import FroalaEditor from 'react-froala-wysiwyg';

const MyFroalaEditor = () => {
  return <FroalaEditor ... />;
};

export default MyFroalaEditor;
// pages/MyPage.tsx

const MyFroalaEditor = dynamic(() => import('../components/MyFroalaEditor'), {
  ssr: false
});

elliottsj avatar Apr 06 '21 15:04 elliottsj