Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
fix(nextjs): building nextjs app by dynamic importing nivo chart
Browse files Browse the repository at this point in the history
  ## problem
  - the nextjs app was unable to build because `@nivo/core` was using a
    file that used commonJS format where nextjs used ESmodule
  - this caused the build to fail
  - probably cause after upgrading `@nivo/core` to v0.83.0

  ## solution
  - lazy load nivo chart component
  - solution obtained from
    - https://nextjs.org/docs/messages/import-esm-externals#possible-ways-to-fix-it
    - plouc/nivo#2310 (comment)

  ## why
  - this will solve the issue of building nextjs app

  ## where
  - ./src/components/Charts/ForwardDestinations.tsx
  - ./src/components/Charts/QueryTypes.tsx

  ## usage
  • Loading branch information
Clumsy-Coder committed Aug 20, 2023
1 parent 3d1a5ab commit f9b5a80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/Charts/ForwardDestinations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import CardContent from '@mui/material/CardContent';
import Grid from '@mui/material/Grid';
import Skeleton from '@mui/material/Skeleton';
import Typography from '@mui/material/Typography';
import { ResponsivePie } from '@nivo/pie';
import dynamic from 'next/dynamic';

import { nivoChartsDarkTheme, chartThemeColours } from '@utils/darkTheme';
import { IForwardedDestinations } from '@utils/url/upstream.types';

const ResponsivePie = dynamic(() => import('@nivo/pie').then((m) => m.ResponsivePie), {
ssr: false,
});

interface Props {
data: IForwardedDestinations | undefined;
isLoading: boolean;
Expand Down
7 changes: 6 additions & 1 deletion src/components/Charts/QueryTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import CardContent from '@mui/material/CardContent';
import Grid from '@mui/material/Grid';
import Skeleton from '@mui/material/Skeleton';
import Typography from '@mui/material/Typography';
import { ResponsivePie } from '@nivo/pie';
import dynamic from 'next/dynamic';


import { nivoChartsDarkTheme, chartThemeColours } from '@utils/darkTheme';
import { IQueryTypes } from '@utils/url/upstream.types';

const ResponsivePie = dynamic(() => import('@nivo/pie').then((m) => m.ResponsivePie), {
ssr: false,
});

interface Props {
data: IQueryTypes | undefined;
isLoading: boolean;
Expand Down

0 comments on commit f9b5a80

Please sign in to comment.