'Receiving the error BlotClass.create is not a function in ReactQuill

I am trying to create a custom font size drop-down for the toolbar in ReactQuill. I decided to strip out the original code for font-size from quilljs and expand on it (as seen below):

import Parchment from 'parchment';

let SizeClass = new Parchment.Attributor.Class('size', 'ql-size', {
  scope: Parchment.Scope.INLINE,
  whitelist: ['8', '9', '10', '11', '12', '13', '14', '16', '18', '24', '36']
});
let SizeStyle = new Parchment.Attributor.Style('size', 'font-size', {
  scope: Parchment.Scope.INLINE,
  whitelist: ['8px', '9px', '10px', '11px', '12px', '13px', '14px', '16px', '18px', '24px', '36px']
});

export { SizeClass, SizeStyle };

When I try to import and register the SizeStyle in my App.js I am receiving the error in the title.

import React, { Component } from 'react';
import ReactQuill, {Quill} from 'react-quill'
import { SizeClass, SizeStyle } from './font-size'

import { ImageDrop } from 'quill-image-drop-module'
import { ImageResize } from 'quill-image-resize-module'

Quill.register(SizeStyle, true)
Quill.register('modules/imageDrop', ImageDrop)
Quill.register('modules/imageResize', ImageResize)

I then have my own HTML toolbar that has all of the size attributes in a drop down:

<div id="toolbar">
        <select className="ql-size">
            <option value="8px"></option>
            <option value="9px"></option>
            <option value="10px"></option>
            <option value="11px"></option>
            <option value="12"></option>
            <option value="13"></option>
            <option value="14"></option>
            <option value="16"></option>
            <option value="18"></option>
            <option value="24"></option>
            <option value="36"></option>
        </select>
  </div>

any suggestions?!



Solution 1:[1]

I was getting the same error until I changed how I was importing Parchment.

Try var Parchment = Quill.import('parchment'); instead of import Parchment from 'parchment';

Solution 2:[2]

I was getting the same above errors so resolved them by calling Parchment.ClassAttributor like this:

var Parchment = Quill.import('parchment');
let config = { scope: Parchment.Scope.BLOCK };
let SpanWrapper = new Parchment.ClassAttributor('span', 'span-wrapper', config);
Quill.register(SpanWrapper, true);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Briaker
Solution 2 Hamza Iqbal