-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highcharts v12 with NextJS #502
Comments
If I remove all the module inits, as the first piece of documentation says, it builds. However, it crashes when trying to render the chart:
|
Hi julioxavierr, thanks for bringing this up! From the Highcharts I agree that the current documentation may not be clear on this. Therefore, let me know if there's still anything unclear, and I'll leave this thread open until the documentation is updated. Kind Regards! |
@KamilKubik thanks for the quick response time. I'll investigate further and figure out if it's an issue with my setup. I've also created a demo with pages router in case it's useful for anyone in the future. |
@julioxavierr thanks for sharing this example! It may be worth mentioning the key difference between the Regards! |
@julioxavierr |
no, I couldn't make it work in Next.js 15 or 14, with @julioxavierr 's demo versions or with latest version of Next.js. I have tried react-router@7 even. I am disabling SSR in every projects, there is no way it runs. I am importing map module like this
or like
I have asked 50 questions to chatgpt as well, tried every suggestions. Even though it works on dev env, it doesn'T build the project, I get TypeError: Cannot read properties of undefined (reading 'Axis') error every time. Any help would be great, I got a project from my company with a 2 weeks deadline and I got stucked at the beginning. |
For anyone having the same problem with Next + Highcharts 12, I have tried every solution on internet and with chatgpt. Only solution was downgrading my highcharts to version 11. I have spent like 4 hours on this. here are the things I have tried
or
none of them worked. By "none of them worked", I mean they run on dev but you get error on build if your next.config.ts is output: "export" (exports only js, css and html, no ssr). for anyone, this is my working (on dev and build) lib versions
|
Hey @Bugrabugra, Have you tried isolating all your highcharts imports into a single component and loading it with |
Hi Bugrabugra! It seems the issue comes from referencing the web API in the node environment during the build. Using the dynamic imports should work as @julioxavierr mentioned, but also, I'd like to refer you to this workaround (to make sure the modules load in the client environment):
|
I have tried dynamic import for "highcharts/modules/map" module at the map component. I haven't tried the way you did, like importing all modules inside a component and calling it with dynamic. |
Thank you so much, I think this approach was the only thing I haven't tried! It worked at both environments, dev and build. Thank you! |
Running into this issue on dev using the recommended method on the client
Am i missing something obvious here? It works fine when I build. |
Having troubles replicating it, I'll poke around and see |
@KamilKubik We ran into an issue with the offline exporting module when using your async loading method. It tries to use some destructured Since we have Highcharts isolated in a single component, loading our wrapper component with |
I do not think the dynamic import issue causes this, but HC Advantage support suggested I ask it here. Thanks for any advice. Thanks, Error log: Chart options example:
Highcharts container:
HighchartsReactContainer:
|
Hi pgeday! Even though I cannot reproduce this specific issue, I've managed to run into similar (hopefully) ones. Here are my thoughts and recommendations:
Also, note that from the Highcharts v12, you should import the modules directly instead of initializing them (see the Upgrade notes section) or the mentioned documentation. Looking forward to your response, |
Hi @KamilKubik, I tested what I understood from the links you provided. I also moved the various import up and down. I also tried to console log if there is a HeatMap and whether it is a function or an object. I get a detailed HeatMap object as if it was imported and in my console shows that the HeatMap is an object, not a function. However, if I change the In my dynamic import I have ssr: false. The part of the app that has the charts only loads in after login and nothing is a static page. Sorry, but what does it mean that you should import the modules directly instead of initializing them. I am importing all the modules per ES6. In the upgrade notes link you shared there is one mention of "import" at v5.0.0. Initialize has 1 mention at v7.1.3, unrelated.
Unfortunately the HeatMap with this code still dies in production. It is good in dev and all the other charts work fine in both environment. I got an example here. I noted that the example has next.js 13.5.1 while mine is at 13.0.5. I am not sure if this may cause the problem. I have everything else the same as in the example. I even dynamic import the HighChartsReactInternal module with ssr: false. I paid for the Advantage support is there a way of a direct look at the code and discuss? Thanks, |
Thanks for your clarification, @pgeday. I've managed to reproduce this issue by using a live environment with files uploaded to the server. It seems to be module-related and, more specifically, to how Next.js treats rendering. Highcharts should be rendered on the client side, and, in theory, we shouldn't encounter any errors when running it in an 'isolated' client-side environment, which we are trying to achieve using the suggestions above. It seems using the ESM imported in an 'isolated' way along with the Next.js v13.0.7 fixes all errors in my environment. I'm sharing the example code below (you should be able to render this component without dynamic import). Could you bump up your version and confirm whether it works for you as well? I can see that upgrading to the latest version is not an option, but hopefully, upgrading to version 13.0.7 shouldn't affect the rest of your application. Also, to answer your question regarding the initialization, the code you shared is the correct approach (importing ESM, also shown below).
Advantage support is provided through an internal support channel, and I believe that I or my colleague will guide you to make it work. As the code is now reproducible, this seems sufficient for debugging, but we are still somewhat dependent on the Next.js specific environment. Let me know if you found the above helpful. Regards! |
I'm using Highcharts with NextJS and when trying to update to Highcharts v12, I get the following error:
From my research, it seems that this issue might be caused by trying to instance a chart on the server-side, which didn't seem to happen before.
While looking at the README of the project, I noticed that the following section was updated with a comment to only init modules if the Highcharts version is below v12.
highcharts-react/README.md
Lines 423 to 436 in 11c276d
However, the NextJS section still says the module should be initiated:
highcharts-react/README.md
Lines 140 to 155 in 11c276d
Which approach should be followed for NextJS? Could the server-side instance attempt be caused by something else?
The text was updated successfully, but these errors were encountered: