ecomfe / echarts-liquidfill

Liquid Fill Chart for Apache ECharts
https://ecomfe.github.io/echarts-liquidfill/example/
BSD 3-Clause "New" or "Revised" License
1.44k stars 621 forks source link

nextjs 下报 ReferenceError: self is not defined #147

Open nshen opened 2 years ago

nshen commented 2 years ago
ReferenceError: self is not defined
    at Object.<anonymous> (/home/nn/github/nextV/node_modules/echarts-liquidfill/dist/echarts-liquidfill.js:10:4)
"echarts": "5.1.0",
"echarts-for-react": "^3.0.1",
"echarts-gl": "^2.0.8",
"echarts-liquidfill": "3.1.0",
mysticaltech commented 2 years ago

The same thing is happening to me, but with other libs! I do not yet know how to fix that error.

nshen commented 2 years ago

hi @mysticaltech this is due to ssr ssg relative things, I solved by dynamic import it

// fix ssr error
if (isClient()) {
  // @ts-ignore
  import('echarts-liquidfill');
}
/**
 * nextjs-utils
 */
export function isClient(): boolean {
  return typeof window !== 'undefined';
}
mysticaltech commented 2 years ago

Thanks for the info, my problem is that I do not even know where the issue comes from as tracing is not showing anywhere! Also not using this very library the issue belongs to.

ksnip_20211201-164101