jodit
jodit copied to clipboard
[ERROR] can't access xxx before initialization
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:
- src/editor.tsx : my simple code
- 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.
I tried using parcel instead of vite, there are different errors:
It works well with rspack, using the rsbuild's default conf:
"scripts": {
"dev": "NODE_ENV=development rspack serve",
"build": "NODE_ENV=production rspack build",
},
It works well using ts + rspack + react , I created a demo jodit_rspack_demo
Can we close it?
@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.
@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?
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.