0

I need to convert this line to next.js dynamic import and also without SSR

import { widget } from "./charting_library/charting_library";

I have tried this one

const widget = dynamic(() => import("./charting_library/charting_library").then((mod) => mod.widget), {
    ssr: false
});

This seems not the correct way and also charting_libray.js file is a compiled js file in a previous project.

enter image description here

Is the problem is my importing method or the js file? If this is importing method how do I fix this?

margherita pizza
  • 6,623
  • 23
  • 84
  • 152
  • Is `./charting_library/charting_library` a React component? `next/dynamic` is used to import React components only. For regular JavaScript libs just use the regular dynamic import as described in [Why am I getting ReferenceError: self is not defined in Next.js when I try to import a client-side library?](https://stackoverflow.com/a/66100185/1870780). – juliomalves Oct 08 '21 at 22:25

1 Answers1

0
const { widget } = await import("./charting_library/charting_library")

Maybe something along those lines might work? As for the SSR side I am not sure if you would need to execute it within a useEffect.

RyanA91
  • 913
  • 7
  • 9