question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Installation fails on Apple Silicon / M1

See original GitHub issue

Steps to reproduce

  • Puppeteer version: 5.5.0
  • Platform / OS version: macOS Big Sur 11.0.1 (Apple Silicon)
  • Node.js version: 15.2.1

What steps will reproduce the problem?

  1. Install puppeteer using yarn or npm

What is the expected result? puppeteer gets installed

What happens instead? Installation fails.

error path-to-project/node_modules/puppeteer: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: path-to-project/node_modules/puppeteer
Output:
The chromium binary is not available for arm64:
If you are on Ubuntu, you can install with:

 apt-get install chromium-browser

path-to-project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:112
            throw new Error();
            ^

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:124
  • Comments:52 (2 by maintainers)

github_iconTop GitHub Comments

322reactions
chetboxcommented, Jul 3, 2021

The solution for me using Chromium from Homebrew was:

brew install chromium
`which chromium`

You will get a security warning. Close it and go to System Preferences > Security & Privacy > General and click Open anyway.

Quit Chromium.

To ~/.zshrc add:

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=`which chromium`

Then restart your terminal.

Edit: Thanks to @gwuah for clarifying that you may need to upgrade Puppeteer. puppeteer: ^9.1.1 should work.

52reactions
neilyiocommented, Mar 1, 2021

A combination of steps from @chetbox and @Lxstr just worked for me. It involved creating a fork of puppeteer and changing a single line of source code. Here’s the exact steps for my project, in ~/Documents/my-project, where trying to install puppeteer gives me the following error:

The chromium binary is not available for arm64
  1. In Terminal, run export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true. This will allow puppeteer to install.
  2. npm install puppeteer. It will skip trying to download chromium and install correctly.
  3. At this point, trying to run puppeteer (for me, using the command npm run test) gives the following error:
Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT
  1. brew install chromium. Run which chromium to make sure it installed properly, it should output the path to the new Chromium executable.

  2. In Terminal, run:

export PUPPETEER_EXECUTABLE_PATH=`which chromium`

Running export PUPPETEER_EXECUTABLE_PATH did not work for me on its own. This is because puppeteer currently hard-codes /usr/bin/chromium-browser in Launcher.ts (compiled to Launched.js) if it detects you’re on arm64. It doesn’t even bother to check the environment variables.

This is where I needed to fork puppeteer. I cloned it to ~/Documents/puppeteer and created a new branch.

  1. Open ~/Documents/puppeteer/src/node/Launcher.ts. Line 180 shows:
      if (os.arch() === 'arm64') {
        chromeExecutable = '/usr/bin/chromium-browser';
     } ....

This is where problem is with the hard-coded path. It immediately assumes where chromium-browser is located, which (at least for me) is not the case with Homebrew installs on Big Sur. The else part of this statement is where it checks your environment variables for configuration (like PUPPETEER_EXECUTABLE_PATH), but it never gets there if you’re on arm64.

By skipping this os.arch() === 'arm64' check, we force puppeteer to look for the environment variables. I just changed line 180 to below:

      if (false) {
        chromeExecutable = '/usr/bin/chromium-browser';
     } ....

Now we need to link our “forked” puppeteer to our original project. First install puppeteer dependencies…

  1. Still in ~/Documents/puppeteer, run npm install to install everything puppeteer needs. Make sure your export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true is still set.
  2. npm run tsc to use the script in puppeteer’s package.json to compile the TypeScript. You need recompile anytime you make a change to the source code in ~/Documents/puppeteer.
  3. npm link to create a global npm “symlink” to your ~/Documents/puppeteer.
  4. Change directory back to your main project, for me it’s ~/Documents/my-project.
  5. npm link puppeteer to point my-project to your forked version of puppeteer.

npm run test again, and everything should work! As @chetbox suggested, you might add these to your ~/.zshrc~ to make sure your environment variables are set correctly when you re-open Terminal:

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=`which chromium`

Hopefully this helps someone else from spending the many hours that I did trying to get this to work. This seems like it would be a pretty simple fix in puppeteer itself, so hopefully we get a real fix in a release soon. For anyone else that can’t wait for a release to run their tests, I hope this is a viable option without having to change anything in your own project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

If an error occurred while updating or installing macOS
The message might say that an error occurred while downloading, preparing, or installing, or that the installer is damaged or could not be ......
Read more >
M1 Apple Silicon pkg installation failed - Jamf Nation Community
The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance.
Read more >
cannot install edgeR on M1 Mac
I am trying to install Rhtslib on macOS Big Sur M1 using R 4.1.0. But I get the following error. And this problem...
Read more >
Restoring Apple Silicon M1 Macs Leading to macOS ...
Several customers who purchased a new Mac with an M1 Apple Silicon app have discovered an issue when attempting to restore the machine, ......
Read more >
Install on Mac | Docker Documentation
Docker Desktop for Apple silicon for detailed information about Docker Desktop for Apple silicon. Troubleshooting describes common problems, workarounds, how to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found