How do I add a npm module to the server environment?

  • I want to make the google-palette module available for use with Chart.js. I assumed I would just need to do an "npm install" for the module in the jsreport folder, but my scripts don't seem to be able to find it via require. I have the option "allowLocalFilesAccess" set to true. Any ideas?

  • administrators

    hi! hmm that should work.. can you share what is the jsreport version you are using? and also can you share all the logs that you get from starting jsreport until you render the report and get the error about not finding google-palette module?

  • We are using 2.2.0 - just installed yesterday actually.

    I have stopped the server, cleared the logs, and restarted.

    jsreport@localhost:/var/jsreport$ jsreport start
    2018-11-29T16:54:33.179Z - info: Initializing jsreport@2.2.0 in development mode using configuration file: jsreport.config.json
    2018-11-29T16:54:33.182Z - info: Searching for available extensions in /var/jsreport/
    2018-11-29T16:54:33.192Z - info: Extensions location cache contains up to date information, skipping crawling in /var/jsreport/
    2018-11-29T16:54:33.197Z - info: Found 31 extensions
    2018-11-29T16:54:33.212Z - debug: Writing extension locations cache to /tmp/jsreport/core/locations.json
    2018-11-29T16:54:33.214Z - debug: Discovered 31 extensions
    2018-11-29T16:54:33.511Z - info: Using extension handlebars
    2018-11-29T16:54:33.517Z - info: Using extension import-export
    2018-11-29T16:54:33.619Z - info: Using extension templates
    2018-11-29T16:54:33.621Z - info: Using extension jsrender
    2018-11-29T16:54:33.622Z - info: Using extension authentication
    2018-11-29T16:54:33.654Z - info: Using extension freeze
    2018-11-29T16:54:33.656Z - info: Using extension cli
    2018-11-29T16:54:33.657Z - info: Using extension express
    2018-11-29T16:54:33.749Z - info: Using extension debug
    2018-11-29T16:54:33.751Z - info: Using extension tags
    2018-11-29T16:54:33.753Z - info: Using extension data
    2018-11-29T16:54:33.755Z - info: Using extension fs-store
    2018-11-29T16:54:33.909Z - info: Using extension authorization
    2018-11-29T16:54:33.911Z - info: Using extension html-to-xlsx
    2018-11-29T16:54:34.026Z - info: html-to-xlsx detected chrome as available html engine
    2018-11-29T16:54:34.026Z - info: Using extension child-templates
    2018-11-29T16:54:34.028Z - info: Using extension browser-client
    2018-11-29T16:54:34.030Z - info: Using extension chrome-pdf
    2018-11-29T16:54:34.035Z - info: Using extension pdf-utils
    2018-11-29T16:54:34.037Z - info: Using extension version-control
    2018-11-29T16:54:34.062Z - info: Using extension reports
    2018-11-29T16:54:34.066Z - info: Using extension text
    2018-11-29T16:54:34.066Z - info: Using extension base
    2018-11-29T16:54:34.068Z - info: Using extension studio
    2018-11-29T16:54:34.086Z - info: Using extension licensing
    2018-11-29T16:54:34.100Z - info: Using extension scripts
    2018-11-29T16:54:34.103Z - info: Using extension assets
    2018-11-29T16:54:34.109Z - info: Using extension scheduling
    2018-11-29T16:54:34.153Z - info: Using extension xlsx
    2018-11-29T16:54:34.200Z - info: Using extension sample-template
    2018-11-29T16:54:34.202Z - info: Using extension resources
    2018-11-29T16:54:34.203Z - info: Using extension public-templates
    2018-11-29T16:54:34.210Z - info: fs store is persisting using fs
    2018-11-29T16:54:34.211Z - info: fs store is synchronizing using fs
    2018-11-29T16:54:34.238Z - info: fs store is loading data
    2018-11-29T16:54:34.290Z - debug: fs store sync is configured to use polling for files watcher
    2018-11-29T16:54:34.340Z - info: fs store is initialized successfully
    2018-11-29T16:54:34.362Z - info: Creating default express app.
    2018-11-29T16:54:34.384Z - info: jsreport server successfully started on http port: 8080
    2018-11-29T16:54:34.385Z - info: fs store emits sockets to synchronize underlying changes with studio
    2018-11-29T16:54:34.401Z - info: Verifying license key free
    2018-11-29T16:54:34.402Z - info: Using free license
    2018-11-29T16:54:34.405Z - info: reporter initialized
    2018-11-29T16:55:15.540Z - info: Starting rendering request 1 (user: admin)
    2018-11-29T16:55:15.543Z - info: Rendering template { name: time_in_zone, recipe: html-with-browser-client, engine: handlebars, preview: true }
    2018-11-29T16:55:15.544Z - debug: Data item not defined for this template.
    2018-11-29T16:55:15.545Z - debug: Resources not defined for this template.
    2018-11-29T16:55:15.550Z - debug: Executing script fetcher
    2018-11-29T16:55:16.893Z - debug: Base url not specified, skipping its injection.
    2018-11-29T16:55:16.894Z - debug: Rendering engine handlebars
    2018-11-29T16:55:17.017Z - debug: Compiled template not found in the cache, compiling
    2018-11-29T16:55:17.057Z - debug: Executing recipe html-with-browser-client
    2018-11-29T16:55:17.079Z - debug: Skipping storing report.
    2018-11-29T16:55:17.096Z - info: Rendering request 1 finished in 1555 ms
    2018-11-29T16:55:32.463Z - info: Starting rendering request 2 (user: admin)
    2018-11-29T16:55:32.464Z - info: Rendering template { name: time_in_zone, recipe: html-with-browser-client, engine: handlebars, preview: true }
    2018-11-29T16:55:32.464Z - debug: Data item not defined for this template.
    2018-11-29T16:55:32.465Z - debug: Resources not defined for this template.
    2018-11-29T16:55:32.466Z - debug: Executing script fetcher
    2018-11-29T16:55:33.515Z - debug: Base url not specified, skipping its injection.
    2018-11-29T16:55:33.516Z - debug: Rendering engine handlebars
    2018-11-29T16:55:33.561Z - debug: Taking compiled template from engine cache
    2018-11-29T16:55:33.573Z - debug: Executing recipe html-with-browser-client
    2018-11-29T16:55:33.604Z - debug: Skipping storing report.
    2018-11-29T16:55:33.642Z - info: Rendering request 2 finished in 1179 ms
    2018-11-29T16:55:54.099Z - debug: OData update on scripts
    2018-11-29T16:55:55.796Z - debug: OData update on assets
    2018-11-29T16:55:58.615Z - info: Starting rendering request 3 (user: admin)
    2018-11-29T16:55:58.616Z - info: Rendering template { name: time_in_zone, recipe: html-with-browser-client, engine: handlebars, preview: true }
    2018-11-29T16:55:58.617Z - debug: Data item not defined for this template.
    2018-11-29T16:55:58.617Z - debug: Resources not defined for this template.
    2018-11-29T16:55:58.626Z - debug: Executing script fetcher
    2018-11-29T16:55:59.685Z - debug: Base url not specified, skipping its injection.
    2018-11-29T16:55:59.685Z - debug: Rendering engine handlebars
    2018-11-29T16:55:59.740Z - warn: Error when processing render request Error while executing templating engine. Unable to find module palette
    Searched paths:
       5 |
       6 | var handlebars = require('handlebars');
    >  7 | var palette = require('palette');
         |               ^
       8 |
       9 | function zoneName(zoneinfo, zoneID) {
      10 |     if (arguments.length < 2)
     Error: Unable to find module palette
    Searched paths:
        at doRequire (/var/jsreport/node_modules/jsreport-core/lib/render/safeSandbox.js:213:11)
        at _require (/var/jsreport/node_modules/jsreport-core/lib/render/safeSandbox.js:54:14)
        at Object.apply (/var/jsreport/node_modules/vm2/lib/contextify.js:288:34)
        at evaluate-template-engine-helpers.js:7:15
        at Script.runInContext (vm.js:107:20)
        at (/var/jsreport/node_modules/vm2/lib/main.js:212:72)
        at run (/var/jsreport/node_modules/jsreport-core/lib/render/safeSandbox.js:171:19)
        at module.exports (/var/jsreport/node_modules/jsreport-core/lib/render/engineScript.js:114:7)
        at IncomingMessage.<anonymous> (/var/jsreport/node_modules/script-manager/lib/worker-servers.js:239:47)
        at IncomingMessage.emit (events.js:182:13)
        at IncomingMessage.EventEmitter.emit (domain.js:460:23)
        at endReadableNT (_stream_readable.js:1094:12)
        at process._tickCallback (internal/process/next_tick.js:63:19)
    2018-11-29T16:55:59.743Z - warn: Error during processing request at

  • administrators

    hmm i replicated your same directory structure (project on /var/jsreport) and started jsreport in the same way (using jsreport start) on my machine (OSX) and i can only see that error when i actually don't have the palette module installed. when the palette is installed on my project (/var/jsreport) then i can run the script normally. are you sure you installed palette correctly on /var/jsreport, for example for me the install of palette required to have some other low level packages listed here, after having those low level things in my machine the install of palette was ok. another check will be to run the npm ls palette command on the /var/jsreport-test directory. you should see a result like this:

    jsreport-server@ /var/jsreport-test
    └── palette@0.1.1

  • administrators

    another weird things, why your logs show other two requests correctly completed before failing in the third request? was the report working before? or does the report render some child templates, header or footer when it is being run?

  • The script had an early error check on its parameters that was backward, so it was failing off a legitimate request.

  • Also.. wow. so the module is called google-palette. And I installed that. And then I referenced it as the wrong thing in the require statement. Yikes. I need a nap! Thanks for your assistance!

Log in to reply

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