mmankai
Posts: 2
Joined: Thu May 11, 2023 6:28 pm

Cannot use highcharts-export-server as node module

I am using node 14. I am trying to run highcharts-export-server as a node module. I am using the following very simple code:

Code: Select all

const exporter = require('highcharts-export-server');

const simpleSettings = {
    type: "png",
    options: {
        "xAxis": {
            "categories": [
                "Jan",
                "Feb",
                "Mar",
                "Apr",
                "May",
                "Jun",
                "Jul",
                "Aug",
                "Sep",
                "Oct",
                "Nov",
                "Dec"
            ]
        },
        "series": [
            {
                "data": [
                    1,
                    3,
                    2,
                    4
                ],
                "type": "line"
            },
            {
                "data": [
                    5,
                    3,
                    4,
                    2
                ],
                "type": "line"
            }
        ]
    }
};
exporter.initPool();
exporter.export(simpleSettings, function (err, res) {
    if (err) {
        console.log("FAILED");
        console.log(err);
    }
    else {
        console.log("SUCCESS");
        console.log(res.data);
    }
    exporter.killPool();
});
It's throwing the following error:

Code: Select all

phantom worker 2 unexpected data - SyntaxError: Use of reserved word 'let' in strict mode

  phantomjs://code/worker.js:658 in loop
{"data":"iVBORw0KGgoAAAANSUhEUgAAAlgAAAGQCAYAAAByNR6YAAAACXBIWX
It outputs following:

Code: Select all

an error occured when rendering the chart: SyntaxError: Unexpected token S in JSON at position 0
Any idea why I am getting this and how to solve it?
jakub.s
Site Moderator
Posts: 1543
Joined: Fri Dec 16, 2022 11:45 am

Re: Cannot use highcharts-export-server as node module

Hi,

Welcome to our forum & thanks for the question!

From what I can see in your code, everything is defined correctly so I'm not sure why it does not work.

I believe that this issue stems from the outdated version of phantomjs installed. Could you try running npm install phantomjs-prebuilt@latest and let me know if that solved your problem?

If it doesn't I'll try to think of something else.

Best regards!
Jakub
Highcharts Developer
mmankai
Posts: 2
Joined: Thu May 11, 2023 6:28 pm

Re: Cannot use highcharts-export-server as node module

Hi,
Thanks for your reply!
I indeed installed the latest version of phantomjs exactly as per your suggestion! I am still getting the exact same issue. I started even with a fresh install with the very simple code above.
jakub.s
Site Moderator
Posts: 1543
Joined: Fri Dec 16, 2022 11:45 am

Re: Cannot use highcharts-export-server as node module

Hi,

Sorry for the delayed response. I'm afraid that I was unable to find anything useful for you and I've forwarded your question to our Export Server Developer team. They'll reach out to you here with an answer.

In the meantime, you could try setting this up for the one last time with the newest version of highcharts-export-server and carefully following the guide from the readme (https://github.com/highcharts/node-expo ... ejs-module).

Apologies and kind regards!
Jakub
Highcharts Developer
jakub.s
Site Moderator
Posts: 1543
Joined: Fri Dec 16, 2022 11:45 am

Re: Cannot use highcharts-export-server as node module

Hi,

I've received an answer regarding your problem.

The problem stems from the fact that Highcharts v11 now uses ES6 (and Highcharts v10 was still in ES5 standard) so now let and const are used instead of vars. PhantomJS is now deprecated and has no support for standards higher than ES5.

However, the good news is that you can get the newest Highcharts code in the ES5 standard (https://code.highcharts.com/11/es5/highcharts.src.js). This has been fixed and merged to master on our GitHub repository (https://github.com/highcharts/node-export-server) but has not yet been published to npm.

There are a few solutions to this problem:

1. Download the package from our GitHub (in package.json in dependencies you could add "highcharts-export-server": "git+https://github.com/highcharts/node-expo ... abd37fd5ec")

2. You could use older versions of Highcharts (before HC v10)

3. You could try switching to the puppeteer version of Export Server which is available on this branch: https://github.com/highcharts/node-expo ... perf-fixes

Keep in mind that it is not the final version (has not officially been released yet) and is currently under the testing phase so not everything might work perfectly.

Let me know if that helps!

Best regards!
Jakub
Highcharts Developer
joedayz
Posts: 11
Joined: Tue May 23, 2023 3:55 pm

Re: Cannot use highcharts-export-server as node module

Hi, thanks for the solutions. I am trying the #1:

"dependencies": {
"async": "2.1.4",
"body-parser": "1.16.0",
"colors": "*",
"cors": "2.8.1",
"express": "4.16.0",
"express-form-data": "2.0.0",
"express-rate-limit": "2.6.0",
"phantomjs-prebuilt": "2.1.14",
"prompt": "*",
"request": "*",
"uuid": "3.0.1",
"highcharts-export-server":"git+https://github.com/highcharts/node-expo ... abd37fd5ec"
},

This is what you are recommending to add in dependencies? Right?


Thanks in advance

Jose
jakub.s
Site Moderator
Posts: 1543
Joined: Fri Dec 16, 2022 11:45 am

Re: Cannot use highcharts-export-server as node module

Hi,

I'm not sure if I fully understand - I initially thought that you were using highcharts-export-server as a node module for your application. In this case, you should add this to your project dependencies, not to highcharts-export-server dependencies.

If you're not using highcharts-export-server as a dependency in your project, you could just simply clone the code available at this link: https://github.com/highcharts/node-expo ... abd37fd5ec and this should solve your issue.

So, the solution depends on the usage of the package.

PS. If you use highcharts-export-server as a node module for your application & you add it to your project dependencies then you should maybe install it with a custom install command like.

package.json for Windows:

Code: Select all

"custom-install": "set ACCEPT_HIGHCHARTS_LICENSE=1 && npm install" //for Windows
"custom-install": "export ACCEPT_HIGHCHARTS_LICENSE=1 && npm install" //for MacOS

and then run npm custom-install to install this package from GitHub.

Kind regards!
Jakub
Highcharts Developer

Return to “Highcharts Usage”