You must be logged in to post your query.
Home › Forums › Chart Support › CanvasJS with Electron/Node.js
Tagged: canvasjs, nodejs
Hi,
I’m trying to use CanvasJS with Electron, but I’m getting the bellow error:
A JavaScript error occurred in the main process Uncaught Exception: import CanvasJS from ‘canvasjs’; ^^^^^^
SyntaxError: Unexpected token import
In my code, I’m requiring CanvasJS as below:
var CanvasJS = require(‘canvasjs’);
Is there a workaround to solve this issue?
Best regards
Solved!
Since Electron doesn’t support ES6 syntaxes, I used babel to convert from ES6 to CommonJS.
Anyway, there is a error on npm module in the following file:
node_modules/canvasjs/src/charts/index.js
The “export” syntaxes must be changed to “import”.
@DanielSore,
Glad that you figured it out. Also, below are the steps to import CanvasJS chart in an electron app.
1. Download the library from our download page and save it in your source folder. 2. To use CanvasJS Chart in your electron app, you need to import CanvasJS from canvasjs.min.js. Please find the below snippet for the same var CanvasJS = require('./canvasjs.min')
var CanvasJS = require('./canvasjs.min')
Here is a complete code example for integrating Chart with an electon app.
__ Priyanka M S Team CanvasJS
You must be logged in to reply to this topic. Login/Register