a month ago
I am experiencing a persistent build failure with my Python and Node.js project. The build process fails with the error sh: 1: npm: not found, even though the environment should have Node.js installed via Nixpacks.
Project Setup:
Builder: I am using the Nixpacks builder.
Build Command: The "Custom Build Command" field in the service settings is empty.
Start Command: The "Start Command" is derived from my Procfile.
Problem:
The build fails during the build phase defined in my nixpacks.toml. The logs clearly indicate that the npm command is not available in the shell's PATH, which is unexpected as nodejs is specified in the nixPkgs setup.
I have tried multiple configurations for nixpacks.toml (separating install/build phases, using generic and specific Nix package names) and have also ensured that Railpacks were not being used. The error persists in all cases. It seems the Node.js package is not being correctly installed or added to the environment by Nixpacks.
Configuration Files:
For your reference, here are the contents of my configuration files:
text
# nixpacks.toml
[phases.setup]
nixPkgs = ["pkgs.python311", "pkgs.nodejs-20_x"]
cmds = ["pip install -r requirements.txt && npm install && npm run build"]
[start]
cmd = "python app.py"
# requirements.txt
flask>=2.3.0
openai>=1.3.0
requests>=2.31.0
youtube-transcript-api>=1.2.2
# package.json
{
"name": "oren",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tailwindcss -i ./static/css/input.css -o ./static/css/output.css --minify"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"autoprefixer": "^10.4.19",
"daisyui": "^4.12.2",
"tailwindcss": "^3.4.4"
}
}
# Procfile
web: python app.py
Could you please investigate why the Nixpacks builder is failing to provide npm in the build environment for this configuration?
Thank you for your help.
4 Replies
a month ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
a month ago
providers = ["...", "node", "python"]
[phases.setup]
nixPkgs = ["pkgs.nodejs", "pkgs.npm", "pkgs.python311"]
[phases.build]
cmds = [
"pip install -r requirements.txt",
"npm install",
"npm run build"
]
[start]
cmd = "python app.py"
Can you use this as your nixpacks.toml file, and share the progress here!
a month ago
This is a classic multi-language setup issue with Nixpacks. The build fails because while you've listed the Node.js package, you haven't explicitly instructed Nixpacks to use its Node.js provider. Nixpacks is likely detecting your Python files, setting up a Python-only environment, and therefore npm
is not added to the PATH
.
For a project with multiple languages, you need to tell Nixpacks to prepare all the necessary environments. You can do this by adding a providers
array to the top of your nixpacks.toml
file.
## How to Fix It
You need to modify your nixpacks.toml
to explicitly declare both the python
and node
providers. This ensures both toolchains are installed and available during the build phase.
Here is the corrected version of your nixpacks.toml
:
Ini, TOML
# nixpacks.toml (Corrected)
providers = ["python", "node"]
[phases.setup]
nixPkgs = ["pkgs.python311", "pkgs.nodejs-20_x"]
[phases.build]
# It's better practice to list commands separately
cmds = [
"pip install -r requirements.txt",
"npm install",
"npm run build"
]
[start]
cmd = "python app.py"
Simply add the providers = ["python", "node"]
line to the top of your file, commit the change, and redeploy. This will instruct Nixpacks to set up both environments correctly, making the npm
command available and allowing your build to proceed.
clashing
providers = ["...", "node", "python"][phases.setup]nixPkgs = ["pkgs.nodejs", "pkgs.npm", "pkgs.python311"][phases.build]cmds = ["pip install -r requirements.txt","npm install","npm run build"][start]cmd = "python app.py"Can you use this as your nixpacks.toml file, and share the progress here!
18 days ago
Any update, blaketiggy
If its solved, then do mark the solution for this issue