getting-started: docker build command fails on yarn install step with error "gyp ERR! find Python"

I’m trying to follow the getting-started tutorial on a Raspberry Pi 4 with Debian 10 installed, but I’m running into some issues. I think they might be related to using the arm architecture, but I’m not sure.

Dockerfile

$ cat Dockerfile
FROM node:12-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

Complete error

$ docker build -t getting-started .
Sending build context to Docker daemon  4.659MB
Step 1/5 : FROM node:12-alpine
 ---> 0409ddca99ab
Step 2/5 : WORKDIR /app
 ---> Using cache
 ---> c211903cef6f
Step 3/5 : COPY . .
 ---> 7a0325ec7af6
Step 4/5 : RUN yarn install --production
 ---> Running in 2df07eae4180
yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
error /app/node_modules/sqlite3: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /app/node_modules/sqlite3
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.11.0
node-pre-gyp info using node@12.20.2 | linux | arm64
node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp info check checked for "/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64/node_sqlite3.node" (not found)
node-pre-gyp http GET https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.0/node-v72-linux-arm64.tar.gz
node-pre-gyp http 403 https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.0/node-v72-linux-arm64.tar.gz
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.0/node-v72-linux-arm64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for sqlite3@4.1.0 and node@12.20.2 (node-v72 ABI, musl) (falling back to source compile with node-gyp)
node-pre-gyp http 403 status code downloading tarball https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.0/node-v72-linux-arm64.tar.gz
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@12.20.2 | linux | arm64
gyp info ok
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@12.20.2 | linux | arm64
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:307:47)
gyp ERR! stack     at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:136:21)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:179:16)
gyp ERR! stack     at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:271:16)
gyp ERR! stack     at exithandler (child_process.js:315:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:327:5)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:470:16)
gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
gyp ERR! System Linux 5.9.0-0.bpo.5-arm64
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64" "--napi_version=7" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
gyp ERR! cwd /app/node_modules/sqlite3
gyp ERR! node -v v12.20.2
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/app/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1022:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
node-pre-gyp ERR! System Linux 5.9.0-0.bpo.5-arm64
node-pre-gyp ERR! command "/usr/local/bin/node" "/app/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /app/node_modules/sqlite3
node-pre-gyp ERR! node -v v12.20.2
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/app/node_modules/sqlite3/lib/binding/node-v72-linux-arm64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn install --production' returned a non-zero code: 1

I tried replacing FROM node:12-alpine with FROM arm64v8/node:12-alpine, but that made no difference.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 20 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @FSund - thank you so much for this issue report, and your suggested fix. Yes I installed Python as you suggested, and it fixed the issue for me.

I’m now on the “Using Bind Mounts” chapter, and hit a similar issue, so I replaced:

docker run -dp 3000:3000 \
    -w /app -v "$(pwd):/app" \
    node:12-alpine \
    sh -c "yarn install && yarn run dev"

with

docker run -dp 3000:3000 \
    -w /app -v "$(pwd):/app" \
    node:12-alpine \
    sh -c "apk --no-cache --virtual build-dependencies add python make g++ && yarn install && yarn run dev"

(again as per your original suggested fix) which fixed the issue for me once again. Just sharing here, in case there are people less familiar with shell scripting who also hit this issue and struggle to fix it.

I had the same issue, running on a new MacBook Pro with the M1 chip

I fixed the error by adding python, but not sure if this is the best solution, as it takes a lot of extra time

FROM node:12-alpine
WORKDIR /app
COPY package.json yarn.lock ./
RUN apk --no-cache --virtual build-dependencies add \
        python \
        make \
        g++ \
&& yarn install --production \
&& apk del build-dependencies
COPY . .
CMD ["node", "src/index.js"]

While the suggested fix here works, I had an issue after updating the Dockerfile to include python. An error occured.

=> ERROR [build-stage 4/9] RUN apk --no-cache --virtual build-dependencies add         p  4.8s
------
 > [build-stage 4/9] RUN apk --no-cache --virtual build-dependencies add         python         make         g++:
#12 0.305 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
#12 3.518 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
#12 4.747 ERROR: unable to select packages:
#12 4.760   python (no such package):
#12 4.760     required by: build-dependencies-20211117.201334[python]

I fixed this by changing the python in the Dockerfile to python2.

I have fixed that on Apple M1 by updating Docker file with the next content:

FROM node:12-alpine
RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN apk --no-cache --virtual build-dependencies add \
        python \
        make \
        g++
RUN yarn install --production
CMD ["node", "src/index.js"]

After that new container should be built:

$ docker build -t getting-started .

Now use the command from the tutorial:

$ docker run -dp 3000:3000 \
     -w /app -v "$(pwd):/app" \
     node:12-alpine \
     sh -c "yarn install && yarn run dev"

The above solutions got close, but didn’t quite work for me. In case this helps anyone here’s what I did…

Recap:

Dockerfile:

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

Command Line:

docker run -dp 3000:3000 \
-w /app -v "$(pwd):/app" \
node:12-alpine \
sh -c "apk add --no-cache python2 g++ make && yarn install && yarn run dev"

After watching/waiting for the logs to complete as instructed in the tutorial, the container is running, can be accessed in the browser at localhost:3000, and updates to src/static/js/app.js are reflected in the browser.

This is my solution

Config in Dockerfile

RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN apk --no-cache --virtual build-dependencies add \
  python \
  make \
  g++
RUN yarn install --production
CMD ["node", "src/index.js"]

Run command

docker run -dp 3000:3000 \
>     -w /app -v "$(pwd):/app" \
>     node:12-alpine \
>     sh -c "apk --no-cache --virtual build-dependencies add python make g++ && yarn install && yarn run dev"

And run command

docker build -t getting-started .

I’m on an M1 Macbook Air and I didn’t get this error where OP did, but I did get it on the Using Bind Mounts section and I resolved it with the command @samjewell posted on 19 Feb. Thanks, community!

The fix suggested by @FSund stopped working in my case with the latest version of Docker.

@IDTitanium’s fix worked (thank you).

Copying node_modules from container before docker run should solve problem:

docker cp <container_id>:/app/node_modules .

Did adding Python help?

I think it’s caused by using a different platform than x86, so it’s falling back to compiling from source

node-pre-gyp WARN Pre-built binaries not found for sqlite3@4.1.0 and node@12.20.2 (node-v72 ABI, musl) (falling back to source compile with node-gyp)

#84 @nguyentuan1696

Your solution worked for me. Apple M1. Updating the docker file and using Python2. Also, using the script to run from the command line adding dependencies alongside the Yarn commands did the trick!

The solution proposed by @nguyentuan1696 (edited slightly with python2):

This is my solution

Config in Dockerfile

RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN apk --no-cache --virtual build-dependencies add \
  python2 \
  make \
  g++
RUN yarn install --production
CMD ["node", "src/index.js"]

Run command

docker run -dp 3000:3000 \
>     -w /app -v "$(pwd):/app" \
>     node:12-alpine \
>     sh -c "apk --no-cache --virtual build-dependencies add python2 make g++ && yarn install && yarn run dev"

Thanks for this one!

Hey @samjewell Thanks a lot. I’m on a M1 and it was getting the same issue. Your fix really helped me.