-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
SSR support #1036
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
Comments
Hello Noah. Could you connect editor js to nextjs ? Im trying the cdn as you said but im not able to make it work. If you can give a little insight, maybe at this time you already make it work on next. |
@noahniuwa you need to wrap the editor as a component as make it ssr false through dynamic import method provided by Next.js. I got the same problem before. you may follow like this Now in the editor you can start adding configs and tool options as per your requirements. |
There is a similar problem in importing in the GatsbyJs project. It works fine in localhost with normal importing. But, at gatsby build it occurs an ssr issue. I solved it for my gatsby js project like this: import the EditorJs component by
for more details, check gatsby js official documentation |
I believe the problem is that the distributed editor.js package module ( A simple fix is to import editor.js dynamically. Here is a simple wrapper we use for React: import * as React from "react";
import { EditorConfig } from "@editorjs/editorjs";
interface EditorJsWrapperProps extends React.ComponentProps<"div"> {
config?: EditorConfig;
}
export default function EditorJsWrapper({
config = {},
...restProps
}: EditorJsWrapperProps): JSX.Element {
const elmtRef = React.useRef<HTMLDivElement>();
React.useEffect(() => {
if (!elmtRef.current) {
return;
}
let editorJs;
(async () => {
const { default: EditorJS } = await import("@editorjs/editorjs");
editorJs = new EditorJS({
...config,
holder: elmtRef.current,
});
})().catch((error): void => console.error(error));
return (): void => {
editorJs.destroy();
};
}, [config]);
return (
<div
{...restProps}
ref={(elmt): void => {
elmtRef.current = elmt;
}}
/>
);
} A proper fix would be to check if editor.js never access |
@neSpecc, @tkesgar mentions that we need a check on Editor.js itself if |
@tkesgar I am using the Editor in Angular, I have the same issue when building for SSR. Because it fails even when the window object is under the globals; |
I don't remember the exact part of code that causes the issue, but I looked for editor.js/src/components/utils.ts Lines 166 to 174 in 33be205
|
Ran into this problem when building a statically rendered SvelteKit app. The build process fails because the package is trying to load |
I am using Angular 11, and I get the window error during ssr only when define |
Hello, I have integrated editor.js in my Angular SSR. when I was trying to load the editor route, the node server encountered an error saying The complete log goes here... ERROR Error: Uncaught (in promise): ReferenceError: self is not defined
ReferenceError: self is not defined
at Object.8941 (C:\home\site\wwwroot\vendors-node_modules_editorjs_code_dist_bundle_js-node_modules_editorjs_editorjs_dist_editor_-77895d.js:1:492565)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Object.9353 (C:\home\site\wwwroot\src_app_shared_fluent-ui_editorjs_editorjs_component_ts-src_app_shared_fluent-ui_editorjs_edi-493a3d.js:1:2836)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Module.2913 (C:\home\site\wwwroot\src_app_questions_qsingle_qsingle_module_ts.js:1:6433)
at Function.__webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976150)
at Object.onInvoke (C:\home\site\wwwroot\main.js:1:470317)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976046)
at Zone.run (C:\home\site\wwwroot\main.js:1:1968989)
at resolvePromise (C:\home\site\wwwroot\main.js:1:1990849)
at resolvePromise (C:\home\site\wwwroot\main.js:1:1989864)
at C:\home\site\wwwroot\main.js:1:1992718
at ZoneDelegate.invokeTask (C:\home\site\wwwroot\main.js:1:1976992)
at Object.onInvokeTask (C:\home\site\wwwroot\main.js:1:469995)
at ZoneDelegate.invokeTask (C:\home\site\wwwroot\main.js:1:1976882)
at Zone.runTask (C:\home\site\wwwroot\main.js:1:1970002)
at drainMicroTaskQueue (C:\home\site\wwwroot\main.js:1:1980199) {
rejection: ReferenceError: self is not defined
at Object.8941 (C:\home\site\wwwroot\vendors-node_modules_editorjs_code_dist_bundle_js-node_modules_editorjs_editorjs_dist_editor_-77895d.js:1:492565)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Object.9353 (C:\home\site\wwwroot\src_app_shared_fluent-ui_editorjs_editorjs_component_ts-src_app_shared_fluent-ui_editorjs_edi-493a3d.js:1:2836)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Module.2913 (C:\home\site\wwwroot\src_app_questions_qsingle_qsingle_module_ts.js:1:6433)
at Function.__webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976150)
at Object.onInvoke (C:\home\site\wwwroot\main.js:1:470317)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976046)
at Zone.run (C:\home\site\wwwroot\main.js:1:1968989),
promise: ZoneAwarePromise [Promise] {
__zone_symbol__state: 0,
__zone_symbol__value: ReferenceError: self is not defined
at Object.8941 (C:\home\site\wwwroot\vendors-node_modules_editorjs_code_dist_bundle_js-node_modules_editorjs_editorjs_dist_editor_-77895d.js:1:492565)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Object.9353 (C:\home\site\wwwroot\src_app_shared_fluent-ui_editorjs_editorjs_component_ts-src_app_shared_fluent-ui_editorjs_edi-493a3d.js:1:2836)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Module.2913 (C:\home\site\wwwroot\src_app_questions_qsingle_qsingle_module_ts.js:1:6433)
at Function.__webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976150)
at Object.onInvoke (C:\home\site\wwwroot\main.js:1:470317)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976046)
at Zone.run (C:\home\site\wwwroot\main.js:1:1968989)
},
zone: Zone {
_parent: Zone {
_parent: null,
_name: '<root>',
_properties: {},
_zoneDelegate: [ZoneDelegate]
},
_name: 'angular',
_properties: { isAngularZone: true },
_zoneDelegate: ZoneDelegate {
_taskCounts: [Object],
zone: [Circular],
_parentDelegate: [ZoneDelegate],
_forkZS: null,
_forkDlgt: null,
_forkCurrZone: null,
_interceptZS: null,
_interceptDlgt: null,
_interceptCurrZone: null,
_invokeZS: [Object],
_invokeDlgt: [ZoneDelegate],
_invokeCurrZone: [Circular],
_handleErrorZS: [Object],
_handleErrorDlgt: [ZoneDelegate],
_handleErrorCurrZone: [Circular],
_scheduleTaskZS: [Object],
_scheduleTaskDlgt: [ZoneDelegate],
_scheduleTaskCurrZone: [Circular],
_invokeTaskZS: [Object],
_invokeTaskDlgt: [ZoneDelegate],
_invokeTaskCurrZone: [Circular],
_cancelTaskZS: [Object],
_cancelTaskDlgt: [ZoneDelegate],
_cancelTaskCurrZone: [Circular],
_hasTaskZS: [Object],
_hasTaskDlgt: [ZoneDelegate],
_hasTaskDlgtOwner: [Circular],
_hasTaskCurrZone: [Circular]
}
},
task: ZoneTask {
_zone: Zone {
_parent: [Zone],
_name: 'angular',
_properties: [Object],
_zoneDelegate: [ZoneDelegate]
},
runCount: 0,
_zoneDelegates: null,
_state: 'notScheduled',
type: 'microTask',
source: 'Promise.then',
data: ZoneAwarePromise [Promise] {
__zone_symbol__state: 0,
__zone_symbol__value: ReferenceError: self is not defined
at Object.8941 (C:\home\site\wwwroot\vendors-node_modules_editorjs_code_dist_bundle_js-node_modules_editorjs_editorjs_dist_editor_-77895d.js:1:492565)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Object.9353 (C:\home\site\wwwroot\src_app_shared_fluent-ui_editorjs_editorjs_component_ts-src_app_shared_fluent-ui_editorjs_edi-493a3d.js:1:2836)
at __webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at Module.2913 (C:\home\site\wwwroot\src_app_questions_qsingle_qsingle_module_ts.js:1:6433)
at Function.__webpack_require__ (C:\home\site\wwwroot\main.js:1:2670977)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976150)
at Object.onInvoke (C:\home\site\wwwroot\main.js:1:470317)
at ZoneDelegate.invoke (C:\home\site\wwwroot\main.js:1:1976046)
at Zone.run (C:\home\site\wwwroot\main.js:1:1968989)
},
scheduleFn: undefined,
cancelFn: undefined,
callback: [Function],
invoke: [Function]
}
} If there is a Solution, Please Suggest. |
For those who still encounter this issue, the problem is that the package's code references browser-specific APIs when executed on server, which does not provide browser-specific APIs. This is an issue with most browser-intensive packages that interact and manipulate browser DOM, since adding a special check for SSR is just not worth it (leads to a lot of To work around the issue, you need to ensure that EditorJS code is not executed on SSR. You can refer to your framework documentation on how to achieve this:
For example, here is how to import it in Next.js: // ComponentThatUseEditorJS.jsx
import EditorJS from "@editorjs/editor"
export default function ComponentThatUseEditorJS() {
return /* your code here */
}
// MyPage.jsx
import dynamic from "next/dynamic"
const ComponentThatUseEditorJs = dynamic(() => import("./ComponentThatUseEditorJs"))
export default function MyPage() {
return (
<div>
<ComponentThatUseEditorJs />
</div>
)
} If you use third-party EditorJS wrappers such as react-editor-js or vue-editor-js, the fix still applies: use your framework's tools to exclude it from SSR. This technique also works with other non-SSR-compatible packages (not only EditorJS). I propose to close this issue since the problem is not on EditorJS side and the workaround is platform-specific. |
+1 |
@Chaitanya-yash if you have domino installed, try
|
@Teebo Yeah man. I did try domino. Ediotr.js still throws an exception about the window. Had the same problem with Localstorage but that is gone now. This one has been haunting me for a couple of days now.
|
@Chaitanya-yash so you've also tried?
|
@Teebo Yeah, I am getting the window error right now upon multiple builds. Self is not coming up |
@Chaitanya-yash can you share you |
|
@Chaitanya-yash let's start by trying to move the below
Move it underneath
|
@Chaitanya-yash the below works for me, I talk it from somewhere online, I still need to make sense of it all. Because some lines use
|
I spun up a new Angular universal project, added EditorJS to it, initialised it |
@Teebo Can you share your the versions for Angular and EditorJS that you are using? |
Can you please use the discussion forums of this repo to sort this out? Thanks. |
This is how I fixed it:
|
I am having the same issue. Did you find a solution for svelte-kit? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
When I try to use by way of a Node.js import, I get an "ReferenceError: window is not defined" error in the browser and can't use it at all.
It works fine when I load it by CDN in the head.
The text was updated successfully, but these errors were encountered: