Need help with EROFS: read-only file system, mkdir '/var/task/logs'



  • Ok.. need some help.

    . been fighting this issue for a while and tried a variety of fixes..when I run Js report under lambda on aws I get this exception:

     "Error: EROFS: read-only file system, mkdir '/var/task/logs'\n    at Object.fs.mkdirSync (fs.js:885:18)\n    at Function.sync (/var/task/node_modules/mkdirp/index.js:71:13)\n    at addTransports (/var/task/node_modules/jsreport/lib/extendConfig.js:152:12)\n    at Reporter.module.exports [as _fnAfterConfigLoaded] (/var/task/node_modules/jsreport/lib/extendConfig.js:171:3)\n    at /var/task/node_modules/jsreport-core/lib/reporter.js:197:17\n    at tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:512:31)\n    at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:569:18)\n    at Promise._settlePromise0 (/var/task/node_modules/bluebird/js/release/promise.js:614:10)\n    at Promise._settlePromises (/var/task/node_modules/bluebird/js/release/promise.js:693:18)\n    at Async._drainQueue (/var/task/node_modules/bluebird/js/release/async.js:133:16)\n    at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:143:10)\n    at Immediate.Async.drainQueues (/var/task/node_modules/bluebird/js/release/async.js:17:14)\n    at runCallback (timers.js:794:20)\n    at tryOnImmediate (timers.js:752:5)\n    at processImmediate [as _immediateCallback] (timers.js:729:5)"
    

    I tried to set the logs to be silent, I assume that was the issue. but it still tries to create the directory I guess. I tried to also use the __dir inside lambda but still same issue.

    I has this working once before... I think I was using jsreport-core.. but I moved to just jsreport.

    @bjrmatos .. any thoughts here man? Must be something simple ?

    I am sure others have solved this..

    Here is my code:

    import config from 'config';
    import AWS from 'aws-sdk';
    import uuid from 'uuid/v4';
    import {
        Logger
    } from './common';
    
    const log = new Logger();
    
    const path = require('path');
    const os = require('os');
    
    const jsreport = require('jsreport')({
        tasks: {
            allowedModules: '*',
            strategy: 'in-process'
        },
        loadConfig: false,
        logger: {
            silent: true
        },
        dataDirectory: path.join(__dirname, 'jsreport'),
        // dataDirectory: path.join(os.tmpdir(), 'jsreport'),
        templatingEngines: {   allowedModules: '*'},
        connectionString: { 'name': 'fs', syncModifications: true }
    });
    jsreport.use(require('jsreport-fs-store')());
    // jsreport.use(require('jsreport-handlebars')());
    // jsreport.use(require('jsreport-phantom-pdf')());
    
    
    
    let initialized = false
    let ready = false
    let readyCallbacks = [];
    
    
    export class Reporting {
        constructor() {
        }
    
        initialize() {
            log.debug("Initialize Reporting");
    
            return new Promise((resolve, reject) => {
                if (!initialized) {
                    initialized = true;
                    log.debug("invoking jsreport.init()");
                    jsreport.init().then(() => {
                        log.debug("init done");
                        ready = true;
                        for (let i = 0; i < readyCallbacks.length; ++i)
                            readyCallbacks[i]();
                        return resolve();
                    }).catch(err => {
                        log.error("JSReport Init error", err);
                        return reject(err);
                    })
                }
                else if (!ready) {
                    log.debug("!ready");
                    readyCallbacks.push(() => { resolve() });
                }
                else {
                    log.debug("jsreport already initialied.");
                    return resolve();
                }
            });
        }
    
        report(body) {
            log.debug("Reporting js rendering", body);
            const self = this;
            return new Promise((resolve, reject) => {
                self.initialize().then(() => {
                    log.debug("rendering");
                    jsreport.render(body).then((response) => {
    
                        log.debug("Response", response);
                        resolve(response);
    
    
                        // log.error("JSReport render error", err);
                        // return reject(err);
                    }).catch(err => {
                        log.error("JSReport render error", err);
                        return reject(err);
                    });
    
                }).catch(err => {
                    log.error("JSReport self init error", err);
                    return reject(err);
                });
            });
        }
    }
    
    
    

  • administrators

    hi!, please specify which version of jsreport you are trying to use, i see that you are using configuration of v1 and v2 so it is not clear to me which one you are using, if possible share the content of your package.json.



  • oh yes.. sorry.

    I would love to move to the latest jsreport once this is working..This has us stumped :-( .. and I tried silent and it is still trying to create the logs folder and getting that error.

    
      "dependencies": {
        "config": "^1.21.0",
        "debug": "^3.0.1",
        "handlebars": "4.0.6",
        "handlebars-helpers": "0.10.0",
        "handlebars-intl": "1.1.2",
        "jsonwebtoken": "8.2.1",
        "jsreport": "1.10.0",
        "mongoose": "^4.13.17",
        "npm": "^6.4.1",
        "upgrade": "1.1.0",
        "uuid": "^3.1.0"
      },
    

    Note: I did find the code making the directory.. and it looks like it is not looking at the 'silent' flag at all.. I assume that is what you mean by config v1 verses v2.. I will try to use the "filename: false" and see what happens

    Also I did try to move to jsrepor 2.2.0 but then it had 3 versions of the handlebars !!.. (and then I got the missing helper error again.. went back to 1.10 and then did not.. so just changing to 2.2.0 make that error come back ) ..
    ....even though I just had the one version of handlebars specified!!.. crazy.. ..

    // winston doesn't create the directories for logs automatically
      // we don't want to do it for developers as well, but also we want to make jsreport with default config running
      // without errors, so we break the consistency here and precreate the logs directory if the config equals to default
      if (reporter.options.logger.file &&
          reporter.options.logger.file.filename === fileTransport.filename &&
          !reporter.options.logger.file.dirname &&
          reporter.options.logger.file.enabled !== false) {
        mkdirp.sync(path.dirname(reporter.options.logger.file.filename))
      }
    

  • administrators

    i see that we always create the logs directory for consistency but according to the logic you can disable it by using this configuration:

    {
      "logger": {
        "silent": true,
        "enabled": false
      }
    }
    


  • yah.. I added enabled: false and got past that error.. but now I am getting this error:.. why is this trying to load the jsreport-studio?

    any idea where that is coming from and how to turn that off ?? :)

    the log is below.. here is my code:

    import config from 'config';
    import AWS from 'aws-sdk';
    import uuid from 'uuid/v4';
    import {
        Logger
    } from './common';
    
    const log = new Logger();
    
    const path = require('path');
    const os = require('os');
    
    const jsreport = require('jsreport')({
        tasks: {
            allowedModules: '*',
        },
        loadConfig: false,
        logger: {
            file: { enabled: false},
            silent: true
        },
        dataDirectory: path.join(os.tmpdir(), 'jsreport'),
        templatingEngines: {   allowedModules: '*'},
        // connectionString: { 'name': 'fs', syncModifications: true }
    });
    // jsreport.use(require('jsreport-fs-store')());
    // jsreport.use(require('jsreport-handlebars')());
    // jsreport.use(require('jsreport-phantom-pdf')());
    
    
    

    and the package.json

      "dependencies": {
        "config": "^1.21.0",
        "debug": "^3.0.1",
        "handlebars": "4.0.6",
        "handlebars-helpers": "0.10.0",
        "handlebars-intl": "1.1.2",
        "jsonwebtoken": "8.2.1",
        "jsreport": "1.10.0",
        "mongoose": "^4.13.17",
        "npm": "^6.4.1",
        "upgrade": "1.1.0",
        "uuid": "^3.1.0"
      },
    
    
    "log": [
            "report error:",
            "Error: EROFS: read-only file system, open '/var/task/node_modules/jsreport-studio/static/dist/1.client.js'\n    at Object.fs.openSync (fs.js:646:18)\n    at Object.fs.writeFileSync (fs.js:1299:33)\n    at Reporter.<anonymous> (/var/task/node_modules/jsreport-studio/lib/studio.js:91:10)\n    at emitOne (events.js:121:20)\n    at Reporter.emit (events.js:211:7)\n    at configureExpressApp (/var/task/node_modules/jsreport-express/lib/reporter.express.js:131:12)\n    at module.exports.<anonymous> (/var/task/node_modules/jsreport-express/lib/reporter.express.js:182:5)\n    at /var/task/node_modules/listener-collection/lib/listenerCollection.js:171:33\n    at /var/task/node_modules/listener-collection/lib/listenerCollection.js:151:16\n    at tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:512:31)\n    at Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:569:18)\n    at Promise._settlePromise0 (/var/task/node_modules/bluebird/js/release/promise.js:614:10)\n    at Promise._settlePromises (/var/task/node_modules/bluebird/js/release/promise.js:693:18)\n    at Async._drainQueue (/var/task/node_modules/bluebird/js/release/async.js:133:16)\n    at Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:143:10)\n    at Immediate.Async.drainQueues (/var/task/node_modules/bluebird/js/release/async.js:17:14)\n    at runCallback (timers.js:794:20)\n    at tryOnImmediate (timers.js:752:5)\n    at processImmediate [as _immediateCallback] (timers.js:729:5)"
        ],
    
    

    any idea what could be making it load the report studio? I have never seen this error before


  • administrators

    hmm so it looks that you are not able to write any file in any directory (even node_modules) when using the lambda, weird that it does not let you modify even node_modules.

    why is this trying to load the jsreport-studio?

    jsreport by default auto discover and load installed extensions. hmm i think you have two options:

    • disable studio by using this configuration: { studio: { enabled: false } }

    or

    • disabling all automatic loading of extensions with: { discover: false }, but using this option will require you to manually call .use() for each extension that you want

    just FYI we don't know yet if jsreport works with lambda, probably you will hit more errors, since lambda has more limitations we need to do some tests to know the exact steps to make it work in lambda, we were busy with the v2 release but i think we will find the time to start looking into lambda support



  • THAT WORKED!!! WOOT!!
    super secret studio-enabled.false flag.. yah! :)

    Thank you @bjrmatos !.

    ok. .so the last thing is to move this to the latest 2.2.0..

    and just for others who might come behind us with this issue on lambda.. here is the final config:

    const jsreport = require('jsreport')({
        tasks: {
            allowedModules: '*',
            strategy: 'in-process'
        },
        loadConfig: false,
        logger: {
            file: { enabled: false},
            silent: true
        },
        studio: { enabled: false },
        allowLocalFilesAccess: true,
        dataDirectory: path.join(os.tmpdir(), 'jsreport'),
        templatingEngines: {   allowedModules: '*'},
      
    });
    

    and the final package.json

    "dependencies": {
        "config": "^1.21.0",
        "debug": "^3.0.1",
        "handlebars": "4.0.6",
        "handlebars-helpers": "0.10.0",
        "handlebars-intl": "1.1.2",
        "jsonwebtoken": "8.2.1",
        "jsreport": "1.10.0",
        "mongoose": "^4.13.17",
        "npm": "^6.4.1",
        "upgrade": "1.1.0",
        "uuid": "^3.1.0"
      },
    

Log in to reply
 

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