Running Cypress on the Apple M1 ARM Architecture using Rosetta 2

January 20, 2021

By The Cypress Team

⚠️
This post is about running Cypress 10.1.x and below on Apple M1 ARM Architecture. Cypress 10.2.0 onwards includes native Apple Silicon support and does not require Rosetta to function. We recommend upgrading Cypress instead of following this guide for an older version. Native M1 builds run up to 3.5x faster than Rosetta-translated builds.

Apple's latest ARM-based M1 chip has begun to make it into the hands of developers across the world.  Naturally, developers would like all of their current software to run as-is on this new and insanely fast architecture.

As it goes with most leaps in technology, software may take a bit of time to catch up with the latest hardware improvements.

Currently, the way to run Cypress on Apple M1 ARM chip is by using Intel emulation with Rosetta 2, Apple's translation layer.

The Problem

At the moment, Cypress cannot be compiled under the ARM-based architecture of new Mac computers and Continuous Integration (CI) providers do not currently offer M1 instances. For these reasons, Cypress is not currently released for the ARM-based architectures and will require Intel emulation for some time.

Therefore, running npm install cypress will install the Intel-based package until these challenges are resolved.

Install Rosetta 2

As a prerequisite to compiling Cypress on an ARM-based Mac, Rosetta 2 can be installed in a single command.

First, manually install Rosetta 2 (accepting the license agreement):

softwareupdate --install-rosetta --agree-to-license

After installation, any program/process may be run under Rosetta 2 prefixing it with arch -x86_64

Furthermore, you can verify what architecture a given program/process was compiled under if they make that information available.

For example, Node provides an arch attribute on its process variable. Thus running node and process.arch inside of the node process will yield x64 for a version of Node compiled using the arch -x86_64 prefix.  A version of Node compiled without a prefix will yield arm64 from process.arch.

Adapting iTerm/Terminal to run under Rosetta 2

To run Terminal/iTerm under Rosetta 2 without the arch -x86_64 prefix it's best to set Terminal/iTerm to always run under Rosetta 2.

Copy iTerm to iTerm Rosetta
  1. In the Applications folder, copy Terminal/iTerm and rename it to Terminal/iTerm Rosetta.
  2. Right-click on the Terminal/iTerm Rosetta app in Applications
  3. Select Get Info
  4. Check the Open using Rosetta option.
Set iTerm Rosetta to "Open using Rosetta", by checking the box after right clicking.

Install nvm and Node under Rosetta 2

The Node Version Manager (nvm) is a "version manager for node.js, designed to be installed per-user, and invoked per-shell".  We can install an x64 and arm64 within nvm to make switching between those easy.

Install x64 Node.js

  1. Launch the Terminal/iTerm Rosetta (created above)
  2. Use nvm to install node.js, for example nvm install v12
  3. Once the installation is complete, run node -p 'process.arch' to show x64
node v12 compiled against Rosetta 2 (x64)

Install arm64 Node.js

  1. Launch the original Terminal/iTerm (non-Rosetta)
  2. Use nvm to install node.js, for example nvm install v14
  3. Once the installation is complete, run node -p 'process.arch' to show armx64
Node v14 compiled against M1 (arm64)

Running Cypress under Rosetta 2

The Cypress Real World App is an open source project implementing a payment application to demonstrate real-world usage of Cypress testing methods, patterns, and workflows.

We can clone it, run yarn install, yarn dev and finally yarn cypress open to see our Cypress tests running on the M1 under Rosetta 2 using the x64 Node.js we installed earlier.

Running our tests is successful and (likely) much faster on this new, innovative “System on a Chip” architecture with incredible performance

Cypress running on MacBook Air M1 (2020) under Rosetta 2