Trouble with deploying Tailwind to Heroku

Viewed 332

I'm trying to deploy a mini-app styled using Tailwind. It's my first time and I've spent the last two days trying to figure it out. This is the closest I got it to deploying per the error log below. When I test it on my local machine, I'm using commands "npm run build-css" and "live-server public". Using these commands it runs on my local machine just fine but when it comes to deploying to Heroku, I'm getting an error. Per my error log, the status goes from "State changed from starting to crashed" and leaves a code H=10 error. I tried several fixes online via googling what others have done with this type of error but I have had no luck. Any help is much appreciated. Thank you.

In the package.json, this is my script.

  "scripts": {
    "start": "npm run build:css",
    "build:css": "tailwindcss build src/styles.css -o public/styles.css"
  }
├── README.md
├── node_modules
├── package-lock.json
├── package.json
├── public
│   ├── index.html
│   ├── index.js
│   └── styles.css
└── src
    └── styles.css

error log:

https://pastebin.com/tctmPVpU

2 Answers

I've experienced this issue previously and fixed it by ensuring the relevant buildpacks were included.

https://devcenter.heroku.com/articles/buildpacks

Double check that you have the correct buildpacks for your application using this command:

heroku buildpacks

In my case I needed the ruby and node buildpacks, with the node pack preceeding the ruby one.

create a server.js file at the root directory containing:

    const path = require('path');
    const express = require('express');
    const app = express();
    const publicPath = path.join(__dirname, '.', 'public');
    const port = process.env.PORT || 3000;
    app.use(express.static(publicPath));
    app.get('*', (req, res) => {
        res.sendFile(path.join(publicPath, 'index.html'));
    });
    app.listen(port, () => {
        console.log('Server is up!');
    });

Change the start script to: node server.js And don't forget to install express package before deploying

Related