xchrisbradley
xchrisbradley

Reputation: 493

Cannot deploy google cloud functions (error: ELIFECYCLE)

This problem is only introduce when adding a new cloud function using puppeteer. The error does not ooccur in local mode using 'firebase serve' only when trying to push it to google cloud functions. This cloud function is the beginning to a bigger project but I wanted to test if I could do the basics on local before live and this is the error im receiving in my logs at the bottom of the page.

I've tried exporting the api routes with just (app) then by making a required path.

const functions = require('firebase-functions');
const app = require('express')();
const puppeteer = require('puppeteer');

const { benchmark } = require('./handlers/benchmark');

// Runs before every route. Launches headless Chrome.
app.all('*', async (req, res, next) => {
    // Note: --no-sandbox is required in this env.
    // Could also launch chrome and reuse the instance
    // using puppeteer.connect()
    res.locals.browser = await puppeteer.launch({
        args: ['--no-sandbox']
    });
    next(); // pass control to next route.
});
// Handler to take screenshots of a URL.
app.get('/benchmark', benchmark);

// Tried this first
exports.api = functions.https.onRequest(app);
// Tried this second
exports.api = functions.https.onRequest((req, res) => {
    if (!req.path) {
        req.url = `/${req.url}`;
    }
    return app(req, res);
});

My benchmark file:

exports.benchmark = async function screenshotHandler(req, res) {
    // const url = '/';
    // req.query.url
    // if (!url) {
    //  return res
    //      .status(400)
    //      .send('Please provide a URL. Example: ?url=https://example.com');
    // }
    const browser = res.locals.browser;
    try {
        const page = await browser.newPage();
        await page.goto('https://www.google.com', {
            waitUntil: 'networkidle2'
        });;
        const buffer = await page.screenshot({ fullPage: true });
        await res.type('image/png').send(buffer);
    } catch (e) {
        res.status(500).send(e.toString());
    }
    await browser.close();
};

Logs:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Users\\bradley_ch\\tools\\node-v10.15.1-win-x64\\node.exe',
1 verbose cli   'C:\\Users\\bradley_ch\\tools\\node-v10.15.1-win-x64\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   '--prefix',
1 verbose cli   'C:\\Users\\bradley_ch\\OneDrive\\Production\\Benchmarking\\reactApp\\functions',
1 verbose cli   'run',
1 verbose cli   'lint' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions@~prelint: functions@
6 info lifecycle functions@~lint: functions@
7 verbose lifecycle functions@~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions@~lint: PATH: C:\Users\bradley_ch\tools\node-v10.15.1-win-x64\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\bradley_ch\OneDrive\Production\Benchmarking\reactApp\functions\node_modules\.bin;C:\Program Files (x86)\RSA SecurID Token Common;c:\Oracle11g\instantclient_11_2;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Sybase\Shared\PowerBuilder\;C:\Users\bradley_ch\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\bradley_ch\AppData\Local\Programs\Python\Python37-32\;C:\Users\bradley_ch\AppData\Local\Programs\Python\Launcher\;C:\Users\bradley_ch\AppData\Local\Microsoft\WindowsApps;C:\Users\bradley_ch\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\bradley_ch\tools\node-v10.15.1-win-x64;C:\Users\bradley_ch\Desktop\Casper\bin;C:\Users\bradley_ch\AppData\Local\Programs\Git\cmd
9 verbose lifecycle functions@~lint: CWD: C:\Users\bradley_ch\OneDrive\Production\Benchmarking\reactApp\functions
10 silly lifecycle functions@~lint: Args: [ '/d /s /c', 'eslint .' ]
11 silly lifecycle functions@~lint: Returned: code: 1  signal: null
12 info lifecycle functions@~lint: Failed to exec lint script
13 verbose stack Error: functions@ lint: `eslint .`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\bradley_ch\tools\node-v10.15.1-win-x64\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\bradley_ch\tools\node-v10.15.1-win-x64\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid functions@
15 verbose cwd C:\Users\bradley_ch\OneDrive\Production\Benchmarking\reactApp
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\\Users\\bradley_ch\\tools\\node-v10.15.1-win-x64\\node.exe" "C:\\Users\\bradley_ch\\tools\\node-v10.15.1-win-x64\\node_modules\\npm\\bin\\npm-cli.js" "--prefix" "C:\\Users\\bradley_ch\\OneDrive\\Production\\Benchmarking\\reactApp\\functions" "run" "lint"
18 verbose node v10.15.1
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error functions@ lint: `eslint .`
22 error Exit status 1
23 error Failed at the functions@ lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Upvotes: 1

Views: 664

Answers (1)

Daniel W.
Daniel W.

Reputation: 32290

12 info lifecycle functions@~lint: Failed to exec lint script
13 verbose stack Error: functions@ lint: `eslint .`

The system does not have or does not know where or what eslint is.

Install it, use absolute path or make your application respect %PATH%.

Upvotes: 1

Related Questions