Rendering issue docker


#1

Hi,
When I’m trying to render a view locally everything is fine.
But when I run it in docker I get the following exception:
Cannot call function style from x.edge view

Someone knows what’s wrong?

Thanks in advance.


#2

@virk could you help me?

This is the code when I want to generate some html:

const moment = require('moment');
moment.locale('nl');

class ShippingOrderController {
async generatePDF({params, response}) {
        const {id} = params;
        let shippingOrder = await ShippingOrder
            .query()
            .where('id', id)
            .with('customer')
            .with('loadingAddress')
            .with('unloadingAddress')
            .with('transporter')
            .with('goods')
            .first();
        shippingOrder = shippingOrder.toJSON();

        const result = await view.render('pdf', {shippingOrder, moment});

This is the error I get from my app in docker:

{
  "error": {
    "message": "Cannot call function style from pdf.edge view",
    "name": "Error",
    "status": 500,
    "frames": [
      {
        "file": "node_modules/edge.js/src/Context/index.js",
        "filePath": "/api/node_modules/edge.js/src/Context/index.js",
        "method": "Context.callFn",
        "line": 286,
        "column": 13,
        "context": {
          "start": 281,
          "pre": "   * @return {Mixed}\n   */\n  callFn (name, args) {\n    const fn = this.resolve(name)\n    if (typeof (fn) !== 'function') {",
          "line": "      throw new Error(`Cannot call function ${name} from ${this.$viewName} view`)",
          "post": "    }\n    return fn.apply(this, args)\n  }\n\n  /**"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/edge.js/src/Template/Runner.js",
        "filePath": "/api/node_modules/edge.js/src/Template/Runner.js",
        "method": "Template.templateFn (eval at run",
        "line": 51,
        "column": 20,
        "context": {
          "start": 46,
          "pre": "     * If template fn is a string, make sure to run\n     * it inside a scope.\n     */\n    if (typeof (this.templateFn) === 'string') {\n      /* eslint no-new-func: \"off\" */",
          "line": "      templateFn = new Function(this.templateFn)",
          "post": "    }\n\n    return templateFn.bind(this.scope)()\n  }\n}"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/edge.js/src/Template/Runner.js",
        "filePath": "/api/node_modules/edge.js/src/Template/Runner.js",
        "method": "Template.eval (eval at run",
        "line": 51,
        "column": 20,
        "context": {
          "start": 46,
          "pre": "     * If template fn is a string, make sure to run\n     * it inside a scope.\n     */\n    if (typeof (this.templateFn) === 'string') {\n      /* eslint no-new-func: \"off\" */",
          "line": "      templateFn = new Function(this.templateFn)",
          "post": "    }\n\n    return templateFn.bind(this.scope)()\n  }\n}"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/edge.js/src/Template/Runner.js",
        "filePath": "/api/node_modules/edge.js/src/Template/Runner.js",
        "method": "TemplateRunner.run",
        "line": 54,
        "column": 39,
        "context": {
          "start": 49,
          "pre": "    if (typeof (this.templateFn) === 'string') {\n      /* eslint no-new-func: \"off\" */\n      templateFn = new Function(this.templateFn)\n    }\n",
          "line": "    return templateFn.bind(this.scope)()",
          "post": "  }\n}\n\nmodule.exports = TemplateRunner\n"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/edge.js/src/Template/index.js",
        "filePath": "/api/node_modules/edge.js/src/Template/index.js",
        "method": "Template.render",
        "line": 322,
        "column": 55,
        "context": {
          "start": 317,
          "pre": "   * @return {String}\n   */\n  render (view, data = {}) {\n    const compiledTemplate = this.compile(view, true)\n    this._makeContext(data)",
          "line": "    return new TemplateRunner(compiledTemplate, this).run()",
          "post": "  }\n\n  /**\n   * Render a view via string\n   *"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/edge.js/src/Edge/index.js",
        "filePath": "/api/node_modules/edge.js/src/Edge/index.js",
        "method": "Edge.render",
        "line": 192,
        "column": 23,
        "context": {
          "start": 187,
          "pre": "\n  /**\n   * docblock defined in template renderer\n   */\n  render (view, ...args) {",
          "line": "    return this.new().render(view, ...args)",
          "post": "  }\n\n  /**\n   * docblock defined in template renderer\n   */"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "node_modules/@adonisjs/framework/src/View/index.js",
        "filePath": "/api/node_modules/@adonisjs/framework/src/View/index.js",
        "method": "View.render",
        "line": 105,
        "column": 24,
        "context": {
          "start": 100,
          "pre": "   * @param  {...Spread} params\n   *\n   * @return {String}\n   */\n  render (...params) {",
          "line": "    return this.engine.render(...params)",
          "post": "  }\n\n  /**\n   * Renders a plain string\n   *"
        },
        "isModule": true,
        "isNative": false,
        "isApp": false
      },
      {
        "file": "app/Controllers/Http/ShippingOrderController.js",
        "filePath": "/api/app/Controllers/Http/ShippingOrderController.js",
        "method": "ShippingOrderController.generatePDF",
        "line": 295,
        "column": 35,
        "context": {
          "start": 290,
          "pre": "            .with('transporter')\n            .with('goods')\n            .first();\n        shippingOrder = shippingOrder.toJSON();\n",
          "line": "        const result = await view.render('pdf', {shippingOrder, moment});",
          "post": "\n        const html5ToPDF = new HTML5ToPDF({\n            inputBody: result,\n            outputPath: `${Helpers.tmpPath()}/tmp.pdf`,\n            renderDelay: 1000,"
        },
        "isModule": false,
        "isNative": false,
        "isApp": true
      }
    ]
  }
}

#3

Can you share the routes file too?


#4

Hi @virk
I don’t think the routes matter. And I’m using the HTML to render a PDF and return a file, but that all works locally.

I did found the problem and maybe I’m doing it wrong in edge
This is the line it breaks on in docker:
{{style("https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css")}}