Nodejs deployments failing with "gyp ERR! find Python"

Hello - My deployments are failing with an error message that node-gyp can’t find python. My fly.toml [build] is configured as follows:

  builder = "paketobuildpacks/builder:base"
  buildpacks = [""]

Any ideas? Thanks in advance!

1 Like


I’m not 100% sure about the buildpack internals, hopefully someone can chime in on that aspect.

However that error is 99.999999% of the time because the project needs node-sass but is including a version of node-sass that is mismatched from the version of NodeJS being used to build that.

The node-sass project has a table showing what versions of node-sass match to watch versions of NodeJS: GitHub - sass/node-sass: Node.js bindings to libsass

You should check your package-lock.json (or yarn lock file) to see exactly what version of node-sass is being used.

I could be wrong about what libraries your Node project needs of course, but that’s where I’ve seen that error the most.

Matching the correct versions alleviates the need for node-gyp (which tries to compile stuff to account for the mismatched versions), and therefore alleviates the need for Python.

No unfortunately same issue. The strange thing is that it continues to build fine from Heroku via Turboku. If I do a new build on Heroku, then pull it over to Fly using Turboku, the build works fine. If I deploy locally using flyctl or if I deploy with a github action it fails with the same error. Here are the logs:

Paketo Buildpack for Yarn Install 0.10.7
  Resolving installation process
    Process inputs:
      yarn.lock -> Found

    Selected default build process: 'yarn install'

  Executing build environment install process
    Running yarn install --ignore-engines --frozen-lockfile --production false --modules-folder /layers/paketo-buildpacks_yarn-install/build-modules/node_modules
failed to execute yarn install: exit status 1
      yarn install v1.22.19
      [1/4] Resolving packages...
      [2/4] Fetching packages...
      [3/4] Linking dependencies...
      warning "@strapi/plugin-graphql > apollo-server-koa@3.10.0" has unmet peer dependency "koa@^2.13.1".
      warning "@strapi/plugin-graphql > graphql-playground-middleware-koa@1.6.22" has unmet peer dependency "koa@^2".
      warning "@strapi/plugin-users-permissions > @strapi/helper-plugin > @strapi/design-system@1.2.5" has unmet peer dependency "@strapi/icons@^1.2.4".
      warning "@strapi/plugin-users-permissions > @strapi/helper-plugin > styled-components@5.3.3" has unmet peer dependency "react-is@>= 16.8.0".
      warning "@strapi/plugin-users-permissions > @strapi/helper-plugin > react-select > @emotion/css > @emotion/babel-plugin@11.10.2" has unmet peer dependency "@babel/core@^7.0.0".
      [4/4] Building fresh packages...
      error /layers/paketo-buildpacks_yarn-install/build-modules/node_modules/better-sqlite3: Command failed.
      Exit code: 1
      Command: prebuild-install || npm run build-release
      Directory: /layers/paketo-buildpacks_yarn-install/build-modules/node_modules/better-sqlite3
      prebuild-install warn install No prebuilt binaries found (target=18.10.0 runtime=node arch=x64 libc= platform=linux)
      > better-sqlite3@7.4.6 build-release
      > node-gyp rebuild --release
      gyp info it worked if it ends with ok
      gyp info using node-gyp@8.4.1
      gyp info using node@18.10.0 | linux | x64
      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 "python3" can be used
      gyp ERR! find Python - "python3" is not in PATH or produced an error
      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 
      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
      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 (/layers/paketo-buildpacks_yarn-install/build-modules/node_modules/node-gyp/lib/find-python.js:330:47)
      gyp ERR! stack     at PythonFinder.runChecks (/layers/paketo-buildpacks_yarn-install/build-modules/node_modules/node-gyp/lib/find-python.js:159:21)
      gyp ERR! stack     at PythonFinder.<anonymous> (/layers/paketo-buildpacks_yarn-install/build-modules/node_modules/node-gyp/lib/find-python.js:202:16)
      gyp ERR! stack     at PythonFinder.execFileCallback (/layers/paketo-buildpacks_yarn-install/build-modules/node_modules/node-gyp/lib/find-python.js:294:16)
      gyp ERR! stack     at exithandler (node:child_process:420:5)
      gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:432:5)
      gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
      gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:289:12)
      gyp ERR! stack     at onErrorNT (node:internal/child_process:476:16)
      gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
      gyp ERR! System Linux 5.12.2
      gyp ERR! command "/layers/paketo-buildpacks_node-engine/node/bin/node" "/layers/paketo-buildpacks_yarn-install/build-modules/node_modules/.bin/node-gyp" "rebuild" "--release"
      gyp ERR! cwd /layers/paketo-buildpacks_yarn-install/build-modules/node_modules/better-sqlite3
      gyp ERR! node -v v18.10.0
      gyp ERR! node-gyp -v v8.4.1
      gyp ERR! not ok
      info Visit for documentation about this command.
ERROR: failed to build: exit status 1
Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 51

Error: Process completed with exit code 1.```

Ah sqlite3, instead of node-sass!

In this case, the lock file is asking for better-sqlite3@7.4.6.

If you check the releases for that library, version 7.4.6 doesn’t have a build for Node 18 (it’s not obvious due to their naming scheme, you’re looking for ...node-v108... I believe). The output there shows that Node 18.10.0 is being used.

Version better-sqlite3@7.5.2+ has support for Node 18.

So you could go down to Node 16 if that’s configurable, or (probably more easy!?), update your dependencies to use the latest version of better-sqlite3, which is v7.6.2.

yarn add node-sass

got me through a similar deploy problem. Or at least moved me to the next problem.

1 Like

I also saw this.

I added node-sass as shown above.

But, I also had to update the Dockerfile to include Python:

RUN apk add --no-cache python3 make g++
# Set environment variable for Python
ENV PYTHON /usr/bin/python3

Note that the ideal is that you use the correct Node version that’s compatible with the packages defined in package.lock (such as sass or sqlite) so you don’t need to compile stuff with gyp when Docker is building an image (when you’re deploying new code).

This often means matching your local Node version with what you’re deploying (the version used in the Docker image created from your Dockerfile).