ant-design-charts
ant-design-charts copied to clipboard
Next js problem window is not defined /node_modules/@antv/g2/lib/geometry/label/
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.
Version : "@ant-design/charts": "^1.3.6" "next": "^12.0.10",
@visiky
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'.
Trace log
Server Error ReferenceError: window is not definedThis 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 });
It is recommended to use sub packages, eg: plots/graphs
const Line = dynamic(() => import('@ant-design/plots').then(({ Line }) => Line), { ssr: false });