R
Railway11mo ago
TheJoker

Dajngo/Tailwind deployment Error: No start command could be found

Project id - 5b1ca7b8-37a6-491d-a6e1-2ca3e0236431 Hi, can someone help me with this error I am getting on build. Its a Django project which is dependant on Tailwind (via Django-Tailwind), I understand it needs Node to function but my pre-deployment research led me to believe that Django-Tailwind would compile the package.json and Nix would automatically install Node and any dependencies on Build (oh so easy right 🙂 ). Obviously this isn't the case. What should I be looking to put into my package.json, which I assume needs a script/command ? I'm a Python/Django person so this is a mystery to me. Any help much appreciated.
85 Replies
Percy
Percy11mo ago
Project ID: 5b1ca7b8-37a6-491d-a6e1-2ca3e0236431
Brody
Brody11mo ago
please share your repo
TheJoker
TheJoker11mo ago
GitHub
GitHub - rob8624/Blog
Contribute to rob8624/Blog development by creating an account on GitHub.
Brody
Brody11mo ago
what is the services root directory set to?
TheJoker
TheJoker11mo ago
Doh, / ---- should be /mysite I take it? let me try
Brody
Brody11mo ago
yes but you are also using a Dockerfile, thus nixpacks is not involved at all, it would be up to you to write the dockerfile that builds your app properly
TheJoker
TheJoker11mo ago
I'm not using Docker, I assumed would be ignored
TheJoker
TheJoker11mo ago
Yea it's created automatically by Wagtail
Brody
Brody11mo ago
and it would be used by railway
TheJoker
TheJoker11mo ago
Ah right Ok, i'll remove it from repo
Brody
Brody11mo ago
so to build this app of yours, you would need node and what node/npm commands do you need to run?
TheJoker
TheJoker11mo ago
Django-Tailwind is reliant on Node in dev i do python manage.py taliwind start to build the css i do python manage.py tailwind build . From their docs ..."This will replace the development build with a bundle optimized for production. No further actions are necessary; you can deploy"
Brody
Brody11mo ago
you would need to write a nixpacks.toml file to add node to your build, and to add extra phases that will run those commands you just spoke of. https://nixpacks.com/docs/guides/configuring-builds
TheJoker
TheJoker11mo ago
Ok thanks for pointing me in the right direction, the file would live in the root directory of the app?
Brody
Brody11mo ago
it would live in the same directory you have the service set to
TheJoker
TheJoker11mo ago
yea ok Ok, looks like Django-Tailwind creates package.json when compiling for production So I pointed nixpacks.toml points towards it... [start] cmd = 'npm start --prefix "theme/static_src"' App builds but crashes and i'm seeing the error in Deploy logs. sh: 1: cross-env: not found npm WARN config production Use --omit=dev instead.
Brody
Brody11mo ago
what does nixpacks detect your app as? a python app or a node app?
TheJoker
TheJoker11mo ago
Sorry i'm unsure on where find that out setup │ nodejs_18, npm-9_x ║ install │ npm ci
start │ npm start --prefix "theme/static_src" ║
Brody
Brody11mo ago
thats exactly how you find out. it says node there, but you have a python app (with node for tailwind). so you need to overwrite the providers to just python in your nixpacks.toml. then you want to add node back to the setup phase as a nix package. then add the phases with the commands you need to run.
TheJoker
TheJoker11mo ago
Right ok, i'm going to sleep on this and look have a go with a fresh brain in the morning, sorry for the questions JS/Node deployment all new to me
Brody
Brody11mo ago
sounds good, give it another try tomorrow and if you cant figure it out i will write the nixpacks.toml file for you
TheJoker
TheJoker11mo ago
Cheers dude much appreciated
Brody
Brody11mo ago
cheers!
TheJoker
TheJoker11mo ago
Yea slept on it, tried some things, still confused as anything! I have read that Django-Tailwind makes the need for Node on the server redundant, is there way for Railway to ignore any Node files on build? Edit....right i'll try pushing to my repo with just the Django and CSS created by Django-Tailwind and not any Node files etc etc
Brody
Brody11mo ago
let's see what you currently have for your nixpacks.toml file
TheJoker
TheJoker11mo ago
I've just left it at
providers = ["...", "python"]
[start]
cmd = 'npm start --prefix "theme/static_src/"'
providers = ["...", "python"]
[start]
cmd = 'npm start --prefix "theme/static_src/"'
package.json
{
"name": "theme",
"version": "3.5.0",
"description": "",
"scripts": {
"start": "npm run dev",
"build": "npm run build:clean && npm run build:tailwind",
"build:clean": "rimraf ../static/css/dist",
"build:tailwind": "cross-env-shell NODE_ENV=production tailwindcss --postcss -i ./src/styles.css -o ../static/css/dist/styles.css --minify",
"dev": "cross-env-shell NODE_ENV=development tailwindcss --postcss -i ./src/styles.css -o ../static/css/dist/styles.css -w",
"tailwindcss": "node ./node_modules/tailwindcss/lib/cli.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/line-clamp": "^0.4.2",
"@tailwindcss/typography": "^0.5.2",
"cross-env": "^7.0.3",
"postcss": "^8.4.14",
"postcss-import": "^15.1.0",
"postcss-nested": "^6.0.0",
"postcss-simple-vars": "^7.0.1",
"rimraf": "^4.1.2",
"tailwindcss": "^3.2.7"
}
}
{
"name": "theme",
"version": "3.5.0",
"description": "",
"scripts": {
"start": "npm run dev",
"build": "npm run build:clean && npm run build:tailwind",
"build:clean": "rimraf ../static/css/dist",
"build:tailwind": "cross-env-shell NODE_ENV=production tailwindcss --postcss -i ./src/styles.css -o ../static/css/dist/styles.css --minify",
"dev": "cross-env-shell NODE_ENV=development tailwindcss --postcss -i ./src/styles.css -o ../static/css/dist/styles.css -w",
"tailwindcss": "node ./node_modules/tailwindcss/lib/cli.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/line-clamp": "^0.4.2",
"@tailwindcss/typography": "^0.5.2",
"cross-env": "^7.0.3",
"postcss": "^8.4.14",
"postcss-import": "^15.1.0",
"postcss-nested": "^6.0.0",
"postcss-simple-vars": "^7.0.1",
"rimraf": "^4.1.2",
"tailwindcss": "^3.2.7"
}
}
Brody
Brody11mo ago
the ... means you are allowing the auto detected node provider, and then only adding python you are also running dev commands that watch for changes, you definitely don't want to do that in a production environment
TheJoker
TheJoker11mo ago
Ok, yea i had no idea
Brody
Brody11mo ago
and you are also missing the extra phases from your nixpacks.toml that run the tailwind commands you have talked about
TheJoker
TheJoker11mo ago
Yea, i've had real trouble understading where and how to add them, i have tried 🙂
Brody
Brody11mo ago
just curious, how many times would you say you've read the nixpacks page I linked?
TheJoker
TheJoker11mo ago
Lots. From a a Django perpective I asked for advice and I'm not sure if this helps the situation but this is the advice i've received.
you only need Node to build the stylesheet. once you have built your CSS file via python manage.py tailwind build, it can be treated just like any other static file

deployment then follows as usual (i.e., Node isn't required anymore)

make sure that whichever server you're building on has Node with NPM, with the correct path configured for the executable
you only need Node to build the stylesheet. once you have built your CSS file via python manage.py tailwind build, it can be treated just like any other static file

deployment then follows as usual (i.e., Node isn't required anymore)

make sure that whichever server you're building on has Node with NPM, with the correct path configured for the executable
Brody
Brody11mo ago
that's spot on, who gave you that advice
TheJoker
TheJoker11mo ago
Reddit. But if Node isn't required anymore, why does it need Node with NPM?
Brody
Brody11mo ago
I'm not sure why you think node isn't required tailwind is an npm package, so you'd need node/npm to download it
TheJoker
TheJoker11mo ago
I'm unsure because this is the first time i've handled anything to do with Node so everything is new
Brody
Brody11mo ago
did you know your Procfile has the wrong casing, not that it would solve your issue also, please remove your node_modules folder from the repo and make sure its in your .gitignore file
TheJoker
TheJoker11mo ago
Ok, thanks for pointing that out will do
Brody
Brody11mo ago
also also, prob shouldnt be commiting your database file to your repo
TheJoker
TheJoker11mo ago
Yea i know, this problem has kinda overtook other things that need changing.
Brody
Brody11mo ago
id recommend using postgres
TheJoker
TheJoker11mo ago
I am
Brody
Brody11mo ago
gotcha, going to try my hand at this nixpacks.toml file now
TheJoker
TheJoker11mo ago
Ok, i'm just looking at other nixpacks files in other repos and relising how bad i am at this 🙂
Brody
Brody11mo ago
heres an example of a nixpacks.toml file with different phases https://github.com/brody192/vite-react-template/blob/main/nixpacks.toml instead of a nixpacks.toml file, i went with a railway.json file with embeded nixpacks config, so that i could have autocomplete, add this railway.json file to your project.
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"providers": ["python"],
"phases": {
"setup": {
"nixPkgs": ["...", "nodejs"]
},
"npm:ci": {
"dependsOn": ["setup"],
"cmds": ["npm ci"]
},
"tailwind:build": {
"dependsOn": ["npm:ci"],
"cmds": ["python manage.py tailwind build"]
}
}
}
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn locallibrary.wsgi"
}
}
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"providers": ["python"],
"phases": {
"setup": {
"nixPkgs": ["...", "nodejs"]
},
"npm:ci": {
"dependsOn": ["setup"],
"cmds": ["npm ci"]
},
"tailwind:build": {
"dependsOn": ["npm:ci"],
"cmds": ["python manage.py tailwind build"]
}
}
}
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn locallibrary.wsgi"
}
}
TheJoker
TheJoker11mo ago
Error: No start command could be found -- shall I remove the nixpacks.toml file? I deleted it's contents assuming it needed to be empty
Brody
Brody11mo ago
yes remove it make sure its in your .gitignore file
TheJoker
TheJoker11mo ago
node_modules removed, nixpacks.toml removed, pushed railway.toml but still get Error: No start command could be found
Brody
Brody11mo ago
whats your root directory set to
TheJoker
TheJoker11mo ago
ok building, forgot i started a new project, corrected root directory its building argg faile don build
Dockerfile:28

-------------------

26 | # tailwind:build phase

27 | COPY . /app/.

28 | >>> RUN python manage.py tailwind build

29 |

30 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c python manage.py tailwind build" did not complete successfully: exit code: 1



Error: Docker build failed
Dockerfile:28

-------------------

26 | # tailwind:build phase

27 | COPY . /app/.

28 | >>> RUN python manage.py tailwind build

29 |

30 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c python manage.py tailwind build" did not complete successfully: exit code: 1



Error: Docker build failed
TheJoker
TheJoker11mo ago
Brody
Brody11mo ago
quoting your build log here
Set the DB_USER environment variable
TheJoker
TheJoker11mo ago
Yea just looking, set env's in Railway I gather? Progress at least thanks so much dude
Brody
Brody11mo ago
yeah a service variable, make absolute sure you are using reference variables https://docs.railway.app/guides/variables#referencing-another-services-variable
TheJoker
TheJoker11mo ago
Ok i need to eat and i'll update 🙂 legend Ok, env's set and all ok....i know get this error when installing Djngo-Taiwind, i assume it related to NPM_BIN_PATH which in development is set to the local path. Not sure how to set this in development?
> [stage-0 10/12] RUN python manage.py tailwind build:

2.172 CommandError:

2.172 It looks like node.js and/or npm is not installed or cannot be found.

2.172

2.172 Visit https://nodejs.org to download and install node.js for your system.

2.172

2.172 If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in settings.py to match path of NPM executable in your system.

2.172

2.172 Example:

2.172 NPM_BIN_PATH = "/usr/local/bin/npm"
> [stage-0 10/12] RUN python manage.py tailwind build:

2.172 CommandError:

2.172 It looks like node.js and/or npm is not installed or cannot be found.

2.172

2.172 Visit https://nodejs.org to download and install node.js for your system.

2.172

2.172 If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in settings.py to match path of NPM executable in your system.

2.172

2.172 Example:

2.172 NPM_BIN_PATH = "/usr/local/bin/npm"
Brody
Brody11mo ago
full build logs please
TheJoker
TheJoker11mo ago
Brody
Brody11mo ago
npm is installed just fine, as you can see the npm ci command finished just fine, this is an issue with django tailwind but lets try giving it the path env it wants
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"providers": ["python"],
"phases": {
"setup": {
"nixPkgs": ["...", "nodejs"],
"cmds": ["export NPM_BIN_PATH=$(which npm)", "echo $NPM_BIN_PATH"]
},
"npm:ci": {
"dependsOn": ["setup"],
"cmds": ["npm ci"]
},
"tailwind:build": {
"dependsOn": ["npm:ci"],
"cmds": ["python manage.py tailwind build"]
}
}
}
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn locallibrary.wsgi"
}
}
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"providers": ["python"],
"phases": {
"setup": {
"nixPkgs": ["...", "nodejs"],
"cmds": ["export NPM_BIN_PATH=$(which npm)", "echo $NPM_BIN_PATH"]
},
"npm:ci": {
"dependsOn": ["setup"],
"cmds": ["npm ci"]
},
"tailwind:build": {
"dependsOn": ["npm:ci"],
"cmds": ["python manage.py tailwind build"]
}
}
}
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn locallibrary.wsgi"
}
}
that echo is just a debug and can be removed later
TheJoker
TheJoker11mo ago
I’m afk for an hour I’ll give it a try then. Hopefully it work many thanks for sticking with me here dude
Brody
Brody11mo ago
no problem!
TheJoker
TheJoker11mo ago
Failed again 😦
> [stage-0 13/15] RUN python manage.py tailwind build:

2.208 CommandError:

2.208 It looks like node.js and/or npm is not installed or cannot be found.

2.208

2.208 Visit https://nodejs.org to download and install node.js for your system.

2.208



2.208 If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in settings.py to match path of NPM executable in your system.

2.208

2.208 Example:

2.208 NPM_BIN_PATH = "/usr/local/bin/npm"

-----

Dockerfile:30

-------------------

28 | # tailwind:build phase

29 | COPY . /app/.

30 | >>> RUN python manage.py tailwind build

31 |

32 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c python manage.py tailwind build" did not complete successfully: exit code: 1



Error: Docker build failed


> [stage-0 13/15] RUN python manage.py tailwind build:

2.208 CommandError:

2.208 It looks like node.js and/or npm is not installed or cannot be found.

2.208

2.208 Visit https://nodejs.org to download and install node.js for your system.

2.208



2.208 If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in settings.py to match path of NPM executable in your system.

2.208

2.208 Example:

2.208 NPM_BIN_PATH = "/usr/local/bin/npm"

-----

Dockerfile:30

-------------------

28 | # tailwind:build phase

29 | COPY . /app/.

30 | >>> RUN python manage.py tailwind build

31 |

32 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c python manage.py tailwind build" did not complete successfully: exit code: 1



Error: Docker build failed


Brody
Brody11mo ago
full logs
TheJoker
TheJoker11mo ago
Brody
Brody11mo ago
I've updated this
TheJoker
TheJoker11mo ago
SAme. here is the log
Brody
Brody11mo ago
under the hood, what command does python manage.py tailwind build run?
TheJoker
TheJoker11mo ago
from the docs ........This will replace the development build with a bundle optimized for production. No further actions are necessary; you can deploy!
Brody
Brody11mo ago
doesnt quite answer the question also, why not just run that command locally and then deploy?
TheJoker
TheJoker11mo ago
It's been run locally. In dev you run python manage.py tailwind build this watches for any styles changes and builds the css occordingly and is contained in it's own Django App.....python manage.py tailwind build compiles the CSS into the needed styles.
Brody
Brody11mo ago
also doesnt answer the question 🫤 you gotta help me help you
TheJoker
TheJoker11mo ago
I know i'm trying..
Brody
Brody11mo ago
i know railway, you have to know your app
TheJoker
TheJoker11mo ago
Totally. Can you expand on this - "why not just run that command locally and then deploy", this was my initial thinking, I have my css file built via the build command ran locally, I wouldn't need Node isntall withing my Railway server at all
Brody
Brody11mo ago
why not run this command locally, then push the changes that this command produces
TheJoker
TheJoker11mo ago
Yes I have thought of that. Railway is seeing a package.json file and attempts to install Node......I assume it's a case of just removing from the repo
Brody
Brody11mo ago
mope, overwrite the providers
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"providers": ["python"]
}
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn locallibrary.wsgi"
}
}
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"providers": ["python"]
}
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn locallibrary.wsgi"
}
}
TheJoker
TheJoker11mo ago
yea ok, let me try and i'll sleep on it. Sorry for all this, one way to learn!
Brody
Brody11mo ago
unless you are about to hope in bed, just update your file and deploy it
TheJoker
TheJoker11mo ago
It published the image and deployed, it then crashed i'm get unrelated dB errors due to not setting localhost
Brody
Brody11mo ago
that's progress
TheJoker
TheJoker11mo ago
Yea i've yet to setup- postgres (within railway) so i'll sort that in morning and go from there
Brody
Brody11mo ago
Sounds good
TheJoker
TheJoker11mo ago
So yea sorry @Brody for taking up so much of your time due to my incompetence with this 🤦‍♂️ Indeed, building the tailwind css into static before committing is the way to do it. No need for node to run anything on Railways end. I got stuck down a rabbit hole.
Want results from more Discord servers?
Add your server