Asset not working in JS Report Single Executable File

  • Asset for External CSS linking is not working in Single Executable JS Report. My header will look like,

            {#asset ./styles.css @encoding=utf8}

    My Directory looks like,

       arpa@ubuntu:~/Documents/static$ ls
       data.json   index.html   jsreport  styles.css  

    Command Executed in Terminal,

    arpa@ubuntu:~/Documents/static$ ./jsreport render  --template.engine=handlebars  --template.recipe=chrome-pdf  --template.content=index.html --data=data.json  --out=out.pdf

    Error shows like Asset file is not found

    rendering has finished with errors:
    A critical error occurred while trying to execute the render command (2). Asset ./styles.css not found (1). 
    caused by error (2):
    -> stack
        at onCriticalError (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:302:19)
        at /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:298:12
    caused by error (1):
    -> meta = {"cause":{},"isOperational":true,"logged":true}
    -> stack
        at readAsset (/snapshot/jsreport/node_modules/jsreport-assets/lib/assets.js:218:15)

  • You need to give jsreport "permissions" to read your local files.
    This can be done with environment variable like this:

    set allowLocalFilesAccess=true&&jsreport render --template...

  • Still It is showing the Same Error.

    arpa@ubuntu:~/Documents/static$ set allowLocalFilesAccess=true&&./jsreport render  --template.engine=handlebars  --template.recipe=chrome-pdf  --template.content=index.html --data=data.json  --out=out.pdf
    starting rendering process..
    rendering has finished with errors:
    A critical error occurred while trying to execute the render command (2). Asset ./styles.css not found (1). 
    caused by error (2):
    -> stack
        at onCriticalError (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:302:19)
        at /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:298:12
    caused by error (1):
    -> meta = {"cause":{},"isOperational":true,"logged":true}
    -> stack
        at readAsset (/snapshot/jsreport/node_modules/jsreport-assets/lib/assets.js:218:15)

    I also gave all permissions for all files.

    arpa@ubuntu:~/Documents/static$ ls -l
    total 247900
    -rwxrwxrwx 1 arpa arpa    464487 Apr 16 19:20 data.json
    -rwxrwxrwx 1 arpa arpa       353 Apr 16 23:03 index.html
    -rwxrwxrwx 1 arpa arpa 253204824 Dec  8 19:25 jsreport
    -rwxrwxrwx 1 arpa arpa        54 Apr 16 18:32 styles.css

  • Hmm, I can't replicate it. The same works for me.
    Could you add the --verbose flag and share the output?

    jsreport render --verbose ...

  • Output with --verbose flag

    arpa@ubuntu:~/Documents/static$ ./jsreport render --verbose  --template.engine=handlebars  --template.recipe=chrome-pdf  --template.content=index.html --data=data.json  --out=out.pdf
    using jsreport instance passed from options
    disabling express extension..
    2021-04-17T08:57:14.580Z - info: Initializing jsreport@2.11.0 in development mode using configuration file: none
    2021-04-17T08:57:14.636Z - info: Setting in-process strategy for rendering
    2021-04-17T08:57:14.646Z - info: Using extension handlebars@2.1.0
    2021-04-17T08:57:14.668Z - info: Using extension tags@2.5.0
    2021-04-17T08:57:14.670Z - info: Using extension templates@2.4.0
    2021-04-17T08:57:14.672Z - info: Using extension puppeteer-compile@1.2.2
    2021-04-17T08:57:14.674Z - debug: skip decompressing chrome in temp because it already exists
    2021-04-17T08:57:14.674Z - info: Using extension authentication@2.6.1
    2021-04-17T08:57:14.746Z - debug: Extension authentication@2.6.1 was disabled
    2021-04-17T08:57:14.746Z - info: Using extension jsrender@2.1.1
    2021-04-17T08:57:14.747Z - info: Using extension cli@2.2.5
    2021-04-17T08:57:14.747Z - info: Using extension import-export@2.1.1
    2021-04-17T08:57:14.748Z - info: Using extension debug@2.1.3
    2021-04-17T08:57:14.749Z - info: Using extension freeze@2.0.0
    2021-04-17T08:57:14.750Z - debug: Extension express@2.8.1 is disabled, skipping
    2021-04-17T08:57:14.751Z - info: Using extension version-control@1.6.0
    2021-04-17T08:57:14.753Z - info: Using extension docx@2.9.0
    2021-04-17T08:57:14.755Z - info: Using extension authorization@2.4.0
    2021-04-17T08:57:14.755Z - debug: Extension authorization@2.4.0 was disabled
    2021-04-17T08:57:14.755Z - info: Using extension data@2.4.0
    2021-04-17T08:57:14.756Z - info: Using extension chrome-pdf@1.10.0
    2021-04-17T08:57:14.759Z - debug: Chrome strategy is dedicated-process
    2021-04-17T08:57:14.759Z - debug: Chrome custom launch options are executablePath=/tmp/jsreport/compile/jsreport-2.11.0-BkQPrWToP/chrome/chrome
    2021-04-17T08:57:14.759Z - info: Using extension child-templates@1.4.0
    2021-04-17T08:57:14.760Z - info: Using extension pdf-utils@1.10.1
    2021-04-17T08:57:14.760Z - info: Using extension pptx@0.7.0
    2021-04-17T08:57:14.763Z - info: Using extension fs-store@2.9.1
    2021-04-17T08:57:14.766Z - debug: Extension fs-store@2.9.1 was disabled
    2021-04-17T08:57:14.766Z - info: Using extension browser-client@2.2.2
    2021-04-17T08:57:14.768Z - info: Using extension reports@2.5.1
    2021-04-17T08:57:14.769Z - info: Using extension text@2.0.0
    2021-04-17T08:57:14.769Z - info: Using extension base@2.0.2
    2021-04-17T08:57:14.770Z - info: Using extension static-pdf@0.4.0
    2021-04-17T08:57:14.770Z - info: Using extension studio@2.10.1
    2021-04-17T08:57:14.791Z - debug: studio request logs are enabled (flush interval: 2000)
    2021-04-17T08:57:14.793Z - info: Using extension licensing@2.2.3
    2021-04-17T08:57:14.795Z - info: Using extension scripts@2.6.0
    2021-04-17T08:57:14.797Z - info: Using extension assets@1.7.0
    2021-04-17T08:57:14.800Z - info: Using extension html-to-xlsx@2.8.3
    2021-04-17T08:57:14.802Z - info: html-to-xlsx detected chrome as available html engine
    2021-04-17T08:57:14.803Z - info: Using extension studio-theme-dark@0.3.0
    2021-04-17T08:57:14.803Z - info: Using extension scheduling@2.5.0
    2021-04-17T08:57:14.815Z - info: Using extension xlsx@2.5.0
    2021-04-17T08:57:14.817Z - info: Using extension sample-template@2.6.1
    2021-04-17T08:57:14.820Z - info: Using extension resources@2.1.0
    2021-04-17T08:57:14.821Z - info: Using extension public-templates@2.2.0
    2021-04-17T08:57:14.822Z - debug: Extension public-templates@2.2.0 was disabled
    2021-04-17T08:57:14.823Z - info: Using memory provider for template store. The saved templates will be lost after restart
    2021-04-17T08:57:14.833Z - debug: studio default theme is: light
    2021-04-17T08:57:14.846Z - info: Verifying license key free
    2021-04-17T08:57:14.848Z - info: Using free license
    2021-04-17T08:57:14.850Z - debug: Creating samples is disabled
    2021-04-17T08:57:14.852Z - info: reporter initialized
    starting rendering process..
    Output configured to: /home/arpa/Documents/static/out.pdf
    rendering with options:
      "template": {
        "engine": "handlebars",
        "recipe": "chrome-pdf",
        "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <title>Document</title>\n    <style>\n      {#asset ./styles.css @encoding=utf8}\n   </style>\n  </head>\n  <body>\n    Here {{msg}}\n  </body>\n</html>\n"
      "data": {
        "msg": "check"
    2021-04-17T08:57:14.873Z - info: Starting rendering request 1 (user: null)
    2021-04-17T08:57:14.874Z - info: Rendering anonymous template { recipe: chrome-pdf, engine: handlebars }
    2021-04-17T08:57:14.875Z - debug: Inline data specified.
    2021-04-17T08:57:14.875Z - debug: Resources not defined for this template.
    2021-04-17T08:57:14.881Z - error: Rendering request 1 finished with error in 9 ms
    2021-04-17T08:57:14.882Z - error: Error when processing render request 1 Asset ./styles.css not found Error: Asset ./styles.css not found
        at readAsset (/snapshot/jsreport/node_modules/jsreport-assets/lib/assets.js:218:15)
    rendering has finished with errors:
    A critical error occurred while trying to execute the render command (2). Asset ./styles.css not found (1). 
    caused by error (2):
    -> stack
        at onCriticalError (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:302:19)
        at /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:298:12
        at processTicksAndRejections (internal/process/task_queues.js:97:5)
    caused by error (1):
    -> meta = {"cause":{},"isOperational":true,"logged":true}
    -> stack
        at readAsset (/snapshot/jsreport/node_modules/jsreport-assets/lib/assets.js:218:15)

  • Is there any demo project for this or any tutorial available?
    If yes, can you please send the link for the video or project zip file?
    Thank you in Advance!!!

  • Maybe it's some kind of permissions problem, but I am not very good at Linux permissions.
    I tried this several times and not able to replicate it.
    Could you try it on a different PC? Maybe there is something wrong in the set up.
    @bjrmatos could you try this as well if it works for you?

  • It worked fine after including JSReport Configuration file. Thank you very much for your support.

Log in to reply

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