using Amchart4, unexpected token...

  • Hello,
    I use 'handlebars' as engine and 'chrome-pdf' as recipe.

    I try to add some graph from AmChart4 ...
    ( i'have allready set the "allowedModules": "*" in the config, i already use 'moment.js' ... )

    So, npm i --save @amcharts/amcharts4
    and in my script i add : const am4core = require('@amcharts/amcharts4/core');

    but i have this error :

    Error while executing templating engine. Unable to require module @amcharts/amcharts4/core. Unexpected token export
    export { System, system } from "./.internal/core/System";
    SyntaxError: Unexpected token export
        at new Script (vm.js:79:7)
        at createScript (vm.js:251:10)
        at Object.runInThisContext (vm.js:303:10)
        at Module._compile (internal/modules/cjs/loader.js:657:28)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Module.require (internal/modules/cjs/loader.js:637:17)
        at require (internal/modules/cjs/helpers.js:22:18). 
      70 |       return result
      71 |     }
    > 72 | const am4core = require('@amcharts/amcharts4/core');
         |                 ^
      73 | 
      74 | const moment = require('moment');
      75 | moment.locale('fr');

    its seem to be es6 related ... but how can i put babel in the project ?

    I try to use cnd instead ...
    So i try to add

    <script src=""></script>
    <script src=""></script>

    in the head of my template ...
    but when i rendering the pdf i have a error that say am4core is not define ...

  • administrators


    for the start the @amcharts/amcharts4 package constains code with es modules, something that does not work in node.js

    the second problem is that you can not use a package like @amcharts/amcharts4 in a jsreport script.. why? because a jsreport script executes server side on node.js and that package expect to be working in the browser not in node.js

    so using the script tags is the correct way to use it.

    i don't how the template that you are using looks like, but i have prepared a demo that shows some basic usage of amcharts, you can find it here. take a closer look at the comment so you can understand why it works.

  • Hooo, thank ...
    i try to put the js code in the helpers.js ... that explain why am4core ins't defined ...

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.