Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import With Webpacker and Typescript #261

Open
jonathanlinford opened this issue May 9, 2024 · 2 comments
Open

Unable to import With Webpacker and Typescript #261

jonathanlinford opened this issue May 9, 2024 · 2 comments

Comments

@jonathanlinford
Copy link

jonathanlinford commented May 9, 2024

Jodit React Version: 4.1.2
Browser: All
OS: Max/Linux
Is React App: True

Code
I encounter the following error when trying to import into my typescript/webpacker project:
Wabpack version: 4.46.0

ERROR in ./app/javascript/components/application/halda-design-system/inputs/ControlledWysiwygWithLabel.tsx 84:38-49
"export 'default' (imported as 'JoditEditor') was not found in 'jodit-react'
    at HarmonyImportSpecifierDependency._getErrors (/Users/jonny/ws/round-robin/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:109:11)
    at HarmonyImportSpecifierDependency.getErrors (/Users/jonny/ws/round-robin/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:68:16)
    at Compilation.reportDependencyErrorsAndWarnings (/Users/jonny/ws/round-robin/node_modules/webpack/lib/Compilation.js:1463:22)
    at /Users/jonny/ws/round-robin/node_modules/webpack/lib/Compilation.js:1258:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jonny/ws/round-robin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/jonny/ws/round-robin/node_modules/tapable/lib/Hook.js:154:20)
    at Compilation.finish (/Users/jonny/ws/round-robin/node_modules/webpack/lib/Compilation.js:1253:28)
    at /Users/jonny/ws/round-robin/node_modules/webpack/lib/Compiler.js:672:17
    at _done (eval at create (/Users/jonny/ws/round-robin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at eval (eval at create (/Users/jonny/ws/round-robin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:80:22)
import React, { ReactElement, useState, useRef } from 'react';
import { useController } from 'react-hook-form';
import ModalWrapper from '../../shared/modals/ModalWrapper';
import JoditEditor from 'jodit-react';

interface ControlledWysiwygWithLabelProps {
  id: string;
  labelClass?: string;
  labelText?: string;
  sublabelHtml?: string;
  init?: any;
  formInputName: string;
  formControl: any;
  defaultValue: any;
  inputRef?: any;
  onClick?: () => void;
  onFocus?: () => void;
  onBlur?: (e: unknown) => void
}

const ControlledWysiwygWithLabel = ({
  id,
  labelClass = 'block text-sm font-medium text-gray-700',
  labelText,
  sublabelHtml,
  init = {},
  formInputName,
  formControl,
  defaultValue,
  inputRef,
  onClick,
  onFocus,
  onBlur,
}: ControlledWysiwygWithLabelProps): ReactElement => {
  const { field: { onChange, value } } = useController({
    name: formInputName,
    control: formControl,
    defaultValue,
  });

  const editor = useRef(null);

  const config = {
    readonly: false // all options from https://xdsoft.net/jodit/doc/
  }

  const handleEditorChange = (newValue: string) => {
    onChange(newValue);
    if (inputRef && typeof inputRef.current !== 'undefined' && inputRef.current !== null) {
      inputRef.current.value = newValue;
    }
  };

  // const [isFullScreen, setIsFullScreen] = useState(false);
  return (
    <>
      {labelText && (
        <>
          <label htmlFor={formInputName} className={labelClass}>
            {labelText}
          </label>
        </>
      )}
      {sublabelHtml && (
        <div className="py-2 text-xs italic text-gray-500">
          {sublabelHtml}
        </div>
      )}
      <div className="mt-1">
        <JoditEditor
          ref={editor}
          value={value}
          config={config}
          onBlur={handleEditorChange} // preferred to use only this option to update the content for performance reasons
          onChange={handleEditorChange}
        />
      </div>
    </>
  );
};

export default ControlledWysiwygWithLabel;

Expected behavior:
Imports and is usable

Actual behavior:
Seems to import fine from the ide (vscode) perspective, but as I run webpacker, I get the following error:

ERROR in ./app/javascript/components/application/halda-design-system/inputs/ControlledWysiwygWithLabel.tsx 84:38-49
"export 'default' (imported as 'JoditEditor') was not found in 'jodit-react'
    at HarmonyImportSpecifierDependency._getErrors (/Users/jonny/ws/round-robin/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:109:11)
    at HarmonyImportSpecifierDependency.getErrors (/Users/jonny/ws/round-robin/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js:68:16)
    at Compilation.reportDependencyErrorsAndWarnings (/Users/jonny/ws/round-robin/node_modules/webpack/lib/Compilation.js:1463:22)
    at /Users/jonny/ws/round-robin/node_modules/webpack/lib/Compilation.js:1258:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jonny/ws/round-robin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/jonny/ws/round-robin/node_modules/tapable/lib/Hook.js:154:20)
    at Compilation.finish (/Users/jonny/ws/round-robin/node_modules/webpack/lib/Compilation.js:1253:28)
    at /Users/jonny/ws/round-robin/node_modules/webpack/lib/Compiler.js:672:17
    at _done (eval at create (/Users/jonny/ws/round-robin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at eval (eval at create (/Users/jonny/ws/round-robin/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:80:22)
ℹ 「wdm」: Failed to compile.
@dev-back55
Copy link

In Next.js app the solution is
import dynamic from 'next/dynamic';
and inside the function
const JoditEditor = dynamic(() => import('jodit-react'), { ssr: false });

@pedroara
Copy link

I am experiencing the exact same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants