I have 2 repos, one that houses all my components that gets packaged and uploaded to a private feed, and one that consumes them. Both repos use React and TS with the repo that consumes the package also running Next.js
I built a charting component using Plottable.js and D3 in the components repo.
Upon installing the latest version of my package onto my main repo, I'm getting build errors that say,
ReferenceError: window is not defined
at Object.StiW (...\source\repos\njs-app\.next\serverless\pages\post.js:47656:19)
at __webpack_require__ (...\source\repos\njs-app\.next\serverless\pages\post.js:23:31)
Going to the first line that it mentions:
var nativeArray = window.Array;
The call to the function that renders the graph and my only call to window within the function that generates the graph
export const ChartComponent = ({data, currentValue}: PlotProps) => {
const makeBasicChart = () => {
...
...
...
if (typeof window !== "undefined") {
window.addEventListener("resize", () => plots.redraw());
}
}
React.useEffect(() => {
makeBasicChart();
});
return (
<ChartContainer id="Chart"/>
);
}
I'm receiving these errors without even including the component on a page.
I'm compiling my components repo with the TS compiler tsc
and haven't had any issues until I included the charting component.
What do I need to do to resolve this issue?