highcharts/node-export-server

v4: getting error

DanielRuf opened this issue · 6 comments

I'm getting the following error:

Cannot create property 'chart' on string '<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="highcharts-root

The config looks like this:

  highcharts: {
    version: 'latest',
    cdnURL: 'https://code.highcharts.com/',
    coreScripts: [ 'highcharts', 'highcharts-more', 'highcharts-3d' ],
    moduleScripts: [
      'stock',
      'map',
      'gantt',
      'exporting',
      'parallel-coordinates',
      'accessibility',
      'boost-canvas',
      'boost',
      'data',
      'data-tools',
      'draggable-points',
      'static-scale',
      'broken-axis',
      'heatmap',
      'tilemap',
      'tiledwebmap',
      'timeline',
      'treemap',
      'treegraph',
      'item-series',
      'drilldown',
      'histogram-bellcurve',
      'bullet',
      'funnel',
      'funnel3d',
      'geoheatmap',
      'pyramid3d',
      'networkgraph',
      'overlapping-datalabels',
      'pareto',
      'pattern-fill',
      'pictorial',
      'price-indicator',
      'sankey',
      'arc-diagram',
      'dependency-wheel',
      'series-label',
      'series-on-point',
      'solid-gauge',
      'sonification',
      'streamgraph',
      'sunburst',
      'variable-pie',
      'variwide',
      'vector',
      'venn',
      'windbarb',
      'wordcloud',
      'xrange',
      'no-data-to-display',
      'drag-panes',
      'debugger',
      'dumbbell',
      'lollipop',
      'cylinder',
      'organization',
      'dotplot',
      'marker-clusters',
      'hollowcandlestick',
      'heikinashi',
      'flowmap',
      'export-data',
      'navigator',
      'textpath'
    ],
    indicatorScripts: [ 'indicators-all' ],
    customScripts: [
      'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js',
      'https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.45/moment-timezone-with-data.min.js'
    ],
    forceFetch: false,
    cachePath: '.cache'
  },
  export: {
    infile: false,
    instr: false,
    options: '<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="highcharts-root" style="font-family: Verdana, sans-serif; font-size: 1rem;" xmlns="http://www.w3.org/2000/svg" width="600" height="219.062" viewBox="0 0 600 219.062" role="img" aria-label="Tool Factory"><desc>Created with Highcharts 11.4.6</desc>...,
    outfile: '....',
    type: 'png',
    constr: 'chart',
    defaultHeight: 400,
    defaultWidth: 600,
    defaultScale: 1,
    height: false,
    width: 600,
    scale: false,
    globalOptions: null,
    themeOptions: false,
    batch: false,
    rasterizationTimeout: 1500
  },
  customLogic: {
    allowCodeExecution: false,
    allowFileResources: false,
    customCode: false,
    callback: false,
    resources: false,
    loadConfig: false,
    createConfig: false
  },
  server: {
    enable: false,
    host: '0.0.0.0',
    port: 7801,
    benchmarking: false,
    proxy: { host: false, port: 8080, timeout: 5000 },
    rateLimiting: {
      enable: false,
      maxRequests: 10,
      window: 1,
      delay: 0,
      trustProxy: false,
      skipKey: false,
      skipToken: false
    },
    ssl: { enable: false, force: false, port: 443, certPath: false }
  },
  pool: {
    minWorkers: 4,
    maxWorkers: 8,
    workLimit: 40,
    acquireTimeout: 5000,
    createTimeout: 5000,
    destroyTimeout: 5000,
    idleTimeout: 30000,
    createRetryInterval: 200,
    reaperInterval: 1000,
    benchmarking: false
  },
  logging: {
    level: 4,
    file: 'highcharts-export-server.log',
    dest: 'log/',
    toConsole: true,
    toFile: true
  },
  ui: { enable: false, route: '/' },
  other: {
    nodeEnv: 'production',
    listenToProcessExits: true,
    noLogo: false,
    hardResetPage: false,
    browserShellMode: true
  },
  debug: {
    enable: false,
    headless: true,
    devtools: false,
    listenToConsole: false,
    dumpio: false,
    slowMo: 0,
    debuggingPort: 9222
  },
  customCode: { allowCodeExecution: 1, callback: null }
}

Ah I see now.

Renamed the customCode section of the options config to the customLogic in order to avoid confusion with the existing customCode property within.

After further checks it seems the documentation is outdated.

Instead of info.data it should be info.result.

After fixing that, it says Error: ENOENT: no such file or directory, open '...\public\resources.json'.
This seems to come from https://github.com/highcharts/node-export-server/blob/master/lib/chart.js#L302-L331.

Hi @DanielRuf,

Thanks for reporting this as well. While I am indeed getting an error when trying to export the chart, it is related to another minor bug (which I will fix), and I cannot reproduce the error related to the resources.json file. Could you provide me with a simple example where this issue is reproduced?

@PaulDalek when I have this config, I get the error:

customLogic: {
    allowCodeExecution: true,
    allowFileResources: false,
    customCode: false,
    callback: false,
    resources: false,
    loadConfig: false,
    createConfig: false
  },

When I use this, I do not get the resources.json error:

customLogic: {
    allowCodeExecution: true,
    allowFileResources: false,
    customCode: false,
    callback: false,
    resources: false,
    loadConfig: false,
    createConfig: false,
    resources: ''
  },

@DanielRuf Ok, I found it. I needed to change the allowCodeExecution to true. The behavior is expected, as it looks for the default resources.json file (just like in the older versions) and, if it doesn't find one, it throws an error which is handled and logs a warning with the error's stack. Other than that, the exporting process works as expected. I agree, though, that instead of displaying the stack, the warning log alone will suffice. I'll prepare a fix for that.

So far I have moved to the CLI where the issue does not exist with the same parameters. So I guess there is some inconsistence between the NodeJS module and the CLI regarding the handling of options / settings and parameters.