ant-design-charts icon indicating copy to clipboard operation
ant-design-charts copied to clipboard

Next js problem window is not defined /node_modules/@antv/g2/lib/geometry/label/

Open radrianhp opened this issue 2 years ago • 1 comments

I got error when build the program ReferenceError: window is not defined at createWorker (/node_modules/@antv/g2/lib/geometry/label/util/createWorker.js) at Object. (/node_modules/@antv/g2/lib/geometry/label/layout/hide-overlap.js) Error in node modules: /node_modules/@antv/g2/lib/geometry/label/util/createWorker.js /node_modules/@antv/g2/lib/geometry/label/layout/hide-overlap.js

Version : "@ant-design/charts": "^1.3.6" "next": "^12.0.10",

ss

radrianhp avatar May 09 '22 02:05 radrianhp

@visiky

lxfu1 avatar May 09 '22 06:05 lxfu1

ant-design-charts is still giving error on loading in next.js..

i'm using 13.0.4 next.js, and i get an error saying 'window is not defined'.

image

Trace log
Server Error ReferenceError: window is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window. Call Stack Object. file:///app/node_modules/@antv/x6/lib/util/polyfill/index.js (39:1) Module._compile node:internal/modules/cjs/loader (1101:14) Object.Module._extensions..js node:internal/modules/cjs/loader (1153:10) Module.load node:internal/modules/cjs/loader (981:32) Function.Module._load node:internal/modules/cjs/loader (822:12) Module.require node:internal/modules/cjs/loader (1005:19) require node:internal/modules/cjs/helpers (102:18) Object. file:///app/node_modules/@antv/x6/lib/util/index.js (19:1) Module._compile node:internal/modules/cjs/loader (1101:14) Object.Module._extensions..js node:internal/modules/cjs/loader (1153:10)

and my solution here:

const Line = dynamic(() => import('@ant-design/charts').then(({ Line }) => Line), { ssr: false });

iidx avatar Nov 23 '22 01:11 iidx

It is recommended to use sub packages, eg: plots/graphs

const Line = dynamic(() => import('@ant-design/plots').then(({ Line }) => Line), { ssr: false });

lxfu1 avatar Feb 13 '23 13:02 lxfu1