Skip to content

Problem: different build and prod environments

Eugene Lazutkin edited this page May 25, 2021 · 3 revisions

In general gyp, which is used to compile a Node binary extension, sniffs the environment it runs in and compiles for the current platform. If the result is being copied and used in a different environment, it can cause an ABI mismatch or other problems. For example, a compiler can be instructed to use specialized CPU instructions, which can be different in a build environment and an execution environment.

The most common case for the difference between environments is Docker, when an image can be built on a developer's Mac-based laptop, and ran on AWS in a Linux-based VM with. On top of an OS difference we are likely to have different CPUs with a different set of features.

If you encounter a problem like that, make sure that your build environment is sufficiently similar to an execution environment. Ideally it should be identical.

In many cases all you need is instead of running npm ci while building a Docker image, run it while executing the image itself.

Relevant links: