jodit icon indicating copy to clipboard operation
jodit copied to clipboard

[ERROR] can't access xxx before initialization

Open newproplus opened this issue 9 months ago • 7 comments

Jodit Version: 4.2.10

Browser: firefox or libwebkit2gtk-4.0-dev in tauri 1.6 OS: debian12 Is React App: True

Code

import React, { useEffect, useRef } from "react";
import { Jodit } from "jodit";
import "jodit/es2021/jodit.fat.min.css";

interface Props {
  id: string;
}

export const RtEditor: React.FC<Props> = ({ id }) => {
  const parentRef = useRef<HTMLDivElement>(null);
  const editorRef = useRef<HTMLTextAreaElement>(null);
  const editor = useRef<Jodit | null>(null);

  useEffect(() => {
    if (editorRef.current) {
      editor.current = Jodit.make(editorRef.current, {});
    }
  }, []);

  return (
    <>
      <div ref={parentRef}>
        <textarea id={id} ref={editorRef} />
      </div>
    </>
  );
};

I made a reo using vite: https://github.com/newproplus/test_jodit , you can test it in browser or tauri.

There are 2 version:

  1. src/editor.tsx : my simple code
  2. src/editor_jr.tsx : a ts version of jodit-react

Both of them have the same issue.

git clone https://github.com/newproplus/test_jodit
pnpm i

# It will works well.
pnpm dev  

# There might be an error like: 
#  1. Uncaught ReferenceError: can't access lexical declaration 'Mb' before initialization.
#  2. Unhandled Promise Rejection: ReferenceError: Cannot access uninitialized variable.
# Neither in browser nor in tauri.
pnpm build && pnpm start 

Actual behavior: The code works well in dev mode, but there will be an error in prod mode: Unhandled Promise Rejection: ReferenceError: Cannot access uninitialized variable.

2024-04-28 16-26-49

2024-04-28 16-28-10

newproplus avatar Apr 28 '24 13:04 newproplus

I tried using parcel instead of vite, there are different errors: 截图 2024-04-29 07-39-52

newproplus avatar Apr 28 '24 23:04 newproplus

It works well with rspack, using the rsbuild's default conf:

 "scripts": {
    "dev": "NODE_ENV=development rspack serve",
    "build": "NODE_ENV=production rspack build",
  },

newproplus avatar Apr 29 '24 00:04 newproplus

It works well using ts + rspack + react , I created a demo jodit_rspack_demo

newproplus avatar Apr 29 '24 06:04 newproplus

Can we close it?

xdan avatar May 11 '24 20:05 xdan

@xdan But the problem has not been solved. It is best that all apps compiled by various packaging tools can be used normally, rather than only apps compiled by rspack not reporting errors.

newproplus avatar May 12 '24 09:05 newproplus

@xdan But the problem has not been solved. It is best that all apps compiled by various packaging tools can be used normally, rather than only apps compiled by rspack not reporting errors.

No, have you tried the latest version? Should this be resolved?

xdan avatar May 13 '24 21:05 xdan

I had the same (or similar) issue with v4.2.10 and vite where the bundles threw this error (albeit not on the same line, but one of its neighbors). After upgrading to 4.2.19 the issue went away.

rshekhtm avatar May 13 '24 23:05 rshekhtm