Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] spawn Unknown system error -8 #63

Closed
jasonlew opened this issue Feb 21, 2023 · 17 comments · Fixed by #76
Closed

[BUG] spawn Unknown system error -8 #63

jasonlew opened this issue Feb 21, 2023 · 17 comments · Fixed by #76
Labels
bug Something isn't working

Comments

@jasonlew
Copy link

Environment

  • chromium Version: chromium-min 110.0.1
  • puppeteer / puppeteer-core Version: puppeteer-core 19.6.3
  • Node.js Version: 18.14.1
  • Lambda / GCF Runtime: running locally first

Expected Behavior

I tried to run the code here.

Current Behavior

Error: spawn Unknown system error -8
    at ChildProcess.spawn (node:internal/child_process:413:11)
    at Module.spawn (node:child_process:757:9)
    at BrowserRunner.start (file:///app/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserRunner.js:91:34)
    at ChromeLauncher.launch (file:///app/node_modules/puppeteer-core/lib/esm/puppeteer/node/ChromeLauncher.js:68:16)

Steps to Reproduce

See above.

@jasonlew jasonlew added the bug Something isn't working label Feb 21, 2023
@jasonlew jasonlew changed the title [BUG] [BUG] spawn Unknown system error -8 Feb 21, 2023
@jasonlew
Copy link
Author

I downgraded to Node 16.19.1, but now I'm getting:

Error: Failed to launch the browser process!
/var/folders/_k/pn98_hgn4cx_y2hw173_g1xw0000gn/T/chromium: /var/folders/_k/pn98_hgn4cx_y2hw173_g1xw0000gn/T/chromium: cannot execute binary file

@Sparticuz
Copy link
Owner

does the file download to /tmp/chromium-pack? What architecture is your cpu, this will only work on x86-64 processors.

@jasonlew
Copy link
Author

I'm running a 2.4 GHz 8-Core Intel Core i9 on Mac. Is it because it won't work on Mac?

Also, is it supposed to work on Node 18 or only up to Node 16?

@Sparticuz
Copy link
Owner

It should support 16 and 18, not sure about 14 since it's EOL in a few weeks. It's compiled specifically for aws lambda, but I don't see any reason why it shouldn't work on the Mac though.

@Kal-Toh
Copy link

Kal-Toh commented Mar 5, 2023

I'm having a similar error. I'm running this on Netlify dev on a m1 Mac to be pushed as a server less function on Netlify.

const puppeteer = require('puppeteer-core');
const chromium = require('@sparticuz/chromium');
exports.handler = async function (event, context) {
  if (event.httpMethod === 'OPTIONS') {
    return {
      statusCode: 200,
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': 'Content-Type',
        'Access-Control-Allow-Methods': 'POST',
      },
      body: '',
    };
  }

  const browser = await puppeteer.launch({
    args: chromium.args,
    executablePath: await chromium.executablePath(),
    headless: chromium.headless,
  });

Returns me the error of:
Error - spawn Unknown system error -8

Object.spawn (node:child_process:757:9)
BrowserRunner.start (/Users/xyz/1.5/Server/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:120:34)
ChromeLauncher.launch (/Users/xyz/1.5/Server/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:97:16)
async exports.handler (/Users/xyz/1.5/Server/functions/quote.js:20:19)

@rfoel
Copy link

rfoel commented Mar 6, 2023

Getting this error on mac M1 too. When I deploy to a lambda it works using this executablePath:

      executablePath: await chromium.executablePath(
        process.env.AWS_EXECUTION_ENV
          ? '/opt/nodejs/node_modules/@sparticuz/chromium/bin'
          : undefined,
      ),

@Kal-Toh
Copy link

Kal-Toh commented Mar 6, 2023

Yeah, the issue for me was that it wasn't compatible with my systems architecture, thus wouldn't work on a local environment. It functions as expected when deployed.

Best thing to do is code>deploy>test>code>deploy>test etc.

@rfoel
Copy link

rfoel commented Mar 7, 2023

@Kal-Toh I've managed to make it work... with playwright. I've installed playwright-core as a dependency and playwright as a devDependency and now it knows how to spawn the browser. I've tried the same solution with puppeteer but I couldn't make it work.

const browser = await playwright.chromium.launch({
      args: chromium.args,
      executablePath: process.env.AWS_EXECUTION_ENV
        ? await chromium.executablePath(
            '/opt/nodejs/node_modules/@sparticuz/chromium/bin',
          )
        : playwright.chromium.executablePath(),
      headless: true
    })

@bhaktatejas922
Copy link

not working for me either on m1 mac

@Sparticuz
Copy link
Owner

executablePath: process.env.AWS_EXECUTION_ENV
        ? await chromium.executablePath(
            '/opt/nodejs/node_modules/@sparticuz/chromium/bin',
          )
        : playwright.chromium.executablePath(),

Yes, this is the correct way to handle arm at this point. You are saying if I'm running in AWS, use this package, otherwise, use playwright's version of chromium. I'm going to document this and close the multiple issues about running on ARM and running Headfully. Thanks for the insight.

@felipeclopes
Copy link

felipeclopes commented Mar 29, 2023

does the file download to /tmp/chromium-pack? What architecture is your cpu, this will only work on x86-64 processors.

When running serverless invoke local --function <name> the standard code doesn't work on x86-64 Mac OS.

const browser = await puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath(),
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    });

Do I need to use playwright to execute locally even on x86 architectures?

PS.: My setup is running fine when deployed (Layer -> AWS Lambda)

@bhaktatejas922
Copy link

bhaktatejas922 commented Mar 29, 2023

on M1 you can do a
arch -x86_64 zsh

in your terminal prior to running and it should work. You'll need to have the x86 packages installed prior to. You can do it by running this for example

npm install --arch=x86 --save puppeteer-core@18.0.5
npm install --arch=x86 --save @sparticuz/chromium@106

@andredezzy
Copy link

Any news how about to execute locally even on M1/M2?

@andredezzy
Copy link

import chromium from '@sparticuz/chromium-min';
import { executablePath } from 'puppeteer';
import * as puppeteer from 'puppeteer-core';

 browser = await puppeteer.launch(
      process.env.NODE_ENV === 'production'
        ? {
            args: chromium.args,
            defaultViewport: chromium.defaultViewport,
            executablePath: await chromium.executablePath(
              'https://drive.google.com/uc?id=1Sw60gty75maoAr2fsIcu-CDJZ5O8RHrm&export=download',
            ),
            headless: chromium.headless,
            ignoreHTTPSErrors: true,
          }
        : {
            headless: false,
            executablePath: executablePath(),
          },
    );

For local development I did this and bow it's working.

@charleswklau
Copy link

@andredezzy

I also use the same approach. It works for me as well.

But have you experienced the PDF output difference? because sometimes I got an extra page, or some inconsistent styles in the remote/production side. It looks perfect in the local development.

@asadimohammad
Copy link

This happened for me because I was on the new macOS "Apple Silicon" in the terminal Apple will not prompt you to install Rosetta which is required for certain apps to run. Simply running softwareupdate --install-rosetta solved the issue for me.

More information about Rosetta here https://support.apple.com/en-gb/HT211861

@sedukhsergey
Copy link

sedukhsergey commented Feb 23, 2024

For me it works with next solution

  1. install Chromium and make a fix because without it the error can happen when you try to launch Cromium.
    https://dev.to/pixelrena/installing-chromium-on-mac-apple-m2-pro-tutorial-4i4i

  2. Use next code for launch pupeeter locally
    Cannot spawn Chromium with custom executablePath on Apple M1 puppeteer/puppeteer#6634 (comment)

On my side it looks like.

import chromium from '@sparticuz/chromium';
import puppeteerCore from 'puppeteer-core';
import puppeteer from 'puppeteer';
...
      if (process.env.STAGE === 'local') {
        browser = await puppeteer.launch({
          executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium',
          args: ['--no-sandbox', '--disable-setuid-sandbox'],
          headless: false,
        });
        console.log('browser', browser);
      }

      if (process.env.STAGE !== 'local') {
        browser = await puppeteerCore.launch({
          args: chromium.args,
          defaultViewport: chromium.defaultViewport,
          executablePath: await chromium.executablePath(),
          headless: chromium.headless,
          ignoreHTTPSErrors: true,
        });
      }
    ...

Mac M1.
Node.js v18.18.2

And from the package.json
"@sparticuz/chromium": "110.0.0",
"puppeteer": "19.6.3",
"puppeteer-core": "19.6.3",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
10 participants