error deploying nodejs

I get the following error when trying to deploy my nodejs app.

#13 9.076 npm ERR! code 1
#13 9.076 npm ERR! path /app/node_modules/node-expat
#13 9.077 npm ERR! command failed
#13 9.077 npm ERR! command sh -c -- node-gyp rebuild
#13 9.078 npm ERR! gyp info it worked if it ends with ok
#13 9.078 npm ERR! gyp info using node-gyp@9.1.0
#13 9.078 npm ERR! gyp info using node@19.1.0 | linux | x64
#13 9.078 npm ERR! gyp ERR! find Python 
#13 9.078 npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
#13 9.078 npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
#13 9.078 npm ERR! gyp ERR! find Python checking if "python3" can be used
#13 9.078 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#13 9.078 npm ERR! gyp ERR! find Python checking if "python" can be used
#13 9.078 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#13 9.078 npm ERR! gyp ERR! find Python 
#13 9.078 npm ERR! gyp ERR! find Python **********************************************************
#13 9.078 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
#13 9.078 npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
#13 9.078 npm ERR! gyp ERR! find Python you can try one of the following options:
#13 9.078 npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
#13 9.078 npm ERR! gyp ERR! find Python   (accepted by both node-gyp and npm)
#13 9.078 npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
#13 9.078 npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
#13 9.078 npm ERR! gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
#13 9.078 npm ERR! gyp ERR! find Python For more information consult the documentation at:
#13 9.078 npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
#13 9.078 npm ERR! gyp ERR! find Python **********************************************************
#13 9.078 npm ERR! gyp ERR! find Python 

The error ends with
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c npm install --production=false]: exit code: 1

Can anyone help with my problem?

Hi,

The error seems to be caused by node-gyp, which needs Python (GitHub - nodejs/node-gyp: Node.js native addon build tool). And … does not find it. Hence the error.

So … the first question would be whether you actually need node-gyp. If you know you don’t need it, you could delete it from package.json, and problem solved. No node-gyp → no python :slight_smile:

If you do, well you would need to have Python. I would guess a remote builder VM (which that output would be from) does not come with it pre-installed. And so you would need to edit your Dockerfile to add a line to install it. What exactly that command would be would depend on the base OS. For example RUN apt-get install python3

It’s relevant to note that node-gyp is almost always a transient dependency of another package and is likely not directly required in your project.

1 Like

Can you post your package.json?

Changing the line that starts with RUN apt-get update to look like the following will get you further:

RUN apt-get update; apt install -y curl python-is-python3 pkg-config

node-gyp is used to compile node addons, typically written in C/C++. Those addons typically require header files to compile against, and lib files to link to. These dependencies can generally be met by installing the appropriate debian package.

{
  "name": "reaktor-backend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "test": "jest --verbose --forceExit"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^1.2.1",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "express-xml-bodyparser": "^0.3.0",
    "mongoose": "^6.8.1",
    "request": "^2.88.2",
    "xml2json": "^0.12.0"
  },
  "devDependencies": {
    "eslint": "^8.30.0",
    "eslint-config-standard": "^17.0.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-n": "^15.6.0",
    "eslint-plugin-promise": "^6.1.1",
    "eslint-plugin-react": "^7.31.11",
    "jest": "^29.3.1",
    "nodemon": "^2.0.20"
  },
  "jest": {
    "testEnvironment": "node"
  }
}

My package-json is as following so I don’t have a node-gyp to delete. But doing this removed the python errors.

RUN apt-get update; apt install -y curl python-is-python3 pkg-config

But now I get the following GYP error:

#11 6.918 npm ERR! code 1
#11 6.918 npm ERR! path /app/node_modules/node-expat
#11 6.919 npm ERR! command failed
#11 6.919 npm ERR! command sh -c -- node-gyp rebuild
#11 6.919 npm ERR! gyp info it worked if it ends with ok
#11 6.919 npm ERR! gyp info using node-gyp@9.1.0
#11 6.919 npm ERR! gyp info using node@19.1.0 | linux | x64
#11 6.919 npm ERR! gyp info find Python using Python version 3.9.2 found at "/usr/bin/python3"
#11 6.919 npm ERR! gyp http GET https://nodejs.org/download/release/v19.1.0/node-v19.1.0-headers.tar.gz
#11 6.919 npm ERR! gyp http 200 https://nodejs.org/download/release/v19.1.0/node-v19.1.0-headers.tar.gz
#11 6.919 npm ERR! gyp http GET https://nodejs.org/download/release/v19.1.0/SHASUMS256.txt
#11 6.919 npm ERR! gyp http 200 https://nodejs.org/download/release/v19.1.0/SHASUMS256.txt
#11 6.919 npm ERR! gyp info spawn /usr/bin/python3
#11 6.919 npm ERR! gyp info spawn args [
#11 6.919 npm ERR! gyp info spawn args   '/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
#11 6.919 npm ERR! gyp info spawn args   'binding.gyp',
#11 6.919 npm ERR! gyp info spawn args   '-f',
#11 6.919 npm ERR! gyp info spawn args   'make',
#11 6.919 npm ERR! gyp info spawn args   '-I',
#11 6.919 npm ERR! gyp info spawn args   '/app/node_modules/node-expat/build/config.gypi',
#11 6.919 npm ERR! gyp info spawn args   '-I',
#11 6.919 npm ERR! gyp info spawn args   '/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
#11 6.919 npm ERR! gyp info spawn args   '-I',
#11 6.919 npm ERR! gyp info spawn args   '/root/.cache/node-gyp/19.1.0/include/node/common.gypi',
#11 6.919 npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
#11 6.919 npm ERR! gyp info spawn args   '-Dvisibility=default',
#11 6.919 npm ERR! gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/19.1.0',
#11 6.919 npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/node-gyp',
#11 6.919 npm ERR! gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/19.1.0/<(target_arch)/node.lib',
#11 6.919 npm ERR! gyp info spawn args   '-Dmodule_root_dir=/app/node_modules/node-expat',
#11 6.919 npm ERR! gyp info spawn args   '-Dnode_engine=v8',
#11 6.919 npm ERR! gyp info spawn args   '--depth=.',
#11 6.919 npm ERR! gyp info spawn args   '--no-parallel',
#11 6.919 npm ERR! gyp info spawn args   '--generator-output',
#11 6.919 npm ERR! gyp info spawn args   'build',
#11 6.919 npm ERR! gyp info spawn args   '-Goutput_dir=.'
#11 6.919 npm ERR! gyp info spawn args ]
#11 6.919 npm ERR! gyp ERR! build error 
#11 6.919 npm ERR! gyp ERR! stack Error: not found: make
#11 6.743 npm ERR! gyp ERR! stack     at getNotFoundError (/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/which/which.js:10:17)
#11 6.743 npm ERR! gyp ERR! stack     at /root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/which/which.js:57:18
#11 6.743 npm ERR! gyp ERR! stack     at new Promise (<anonymous>)
#11 6.743 npm ERR! gyp ERR! stack     at step (/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/which/which.js:54:21)
#11 6.744 npm ERR! gyp ERR! stack     at /root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/which/which.js:71:22
#11 6.744 npm ERR! gyp ERR! stack     at new Promise (<anonymous>)
#11 6.744 npm ERR! gyp ERR! stack     at subStep (/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/which/which.js:69:33)
#11 6.744 npm ERR! gyp ERR! stack     at /root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/which/which.js:80:22
#11 6.744 npm ERR! gyp ERR! stack     at /root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/isexe/index.js:42:5
#11 6.744 npm ERR! gyp ERR! stack     at /root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
#11 6.744 npm ERR! gyp ERR! System Linux 5.12.2
#11 6.744 npm ERR! gyp ERR! command "/root/.volta/tools/image/node/19.1.0/bin/node" "/root/.volta/tools/image/node/19.1.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#11 6.744 npm ERR! gyp ERR! cwd /app/node_modules/node-expat
#11 6.744 npm ERR! gyp ERR! node -v v19.1.0
#11 6.744 npm ERR! gyp ERR! node-gyp -v v9.1.0
#11 6.744 npm ERR! gyp ERR! not ok
#11 6.744 
#11 6.745 npm ERR! A complete log of this run can be found in:
#11 6.745 npm ERR!     /root/.npm/_logs/2022-12-27T11_16_26_544Z-debug-0.log
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c npm install]: exit code: 1

I’m pretty sure i don’t need the node-gyp so would be helpful ohw to get rid of it from the project.

Good news, that problem is easy to address, and appears to be the last error. Try adding build-essential to the install line, thus:

RUN apt-get update; apt install -y curl python-is-python3 pkg-config build-essential
1 Like

This fixed the problems! Thanks!