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

ReferenceError: window is not defined on next.js #149

Open
Tiago138 opened this issue Sep 26, 2022 · 2 comments
Open

ReferenceError: window is not defined on next.js #149

Tiago138 opened this issue Sep 26, 2022 · 2 comments

Comments

@Tiago138
Copy link

Hi, I'm trying to use this chart on next.js but I'm getting the ReferenceError: window is not defined on next.js.
I don't know what it can be since I'm already using other echarts charts on my project, I only get this erro, when I import echarts wordcloud.
If anyone here know what can be causing the error I really would appreciate the help.

Thanks guys for your awesome project.

@Tiago138
Copy link
Author

I get this on my console

error - node_modules/echarts-wordcloud/src/layout.js (12:0) @ eval
ReferenceError: window is not defined
null

@achaitanyasai
Copy link

achaitanyasai commented May 21, 2023

I have faced the same issue recently, and I was able to resolve by importing echarts-wordcloud on the client side:

import {useEffect, useState} from "react";

import * as echarts from 'echarts/core';
import {CanvasRenderer} from "echarts/renderers";
import {
    TitleComponent,
} from 'echarts/components';
echarts.use([
    TitleComponent,
    CanvasRenderer
]);

export default function WordCloudChartClientComponent(props) {
   const [WordCloudInitialized, setWordCloudInitialized] = useState(false);
   useEffect(() => {
      // Initialize ECharts Word Cloud.
      const initWordCloud = async() => {
        await import('echarts-wordcloud');
        setWordCloudInitialized(true)
      }
      initWordCloud();
  }, []);

  return (
    <>
        WordCloudInitialized ?
             <SomeComponentDependentOnWordCloud echarts={echarts} />
            : <p>Loading...</p>
    </>
  );

}

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

2 participants