2

I've tried other solutions found here but none of them work for me, right now my start script is like this

"build": "tsc && vite build",
"start": "vite preview --host 0.0.0.0 --port $PORT",

when I run this I get this error

2022-12-01T02:51:01.843831+00:00 app[web.1]: sh: 1: vite: not found

I set NPM_CONFIG_PRODUCTIONto falsein order to avoid prune my devDependencies because vite is listed there, but I'm still receiving the same error

Additionally, I tried run a static server

"start": "node server.cjs",

and my server file is this

const express = require('express')
const serveStatic = require('serve-static')
const path = require('path')



const app = express()

//here we are configuring dist to serve app files
app.use('/', serveStatic(path.join(__dirname, '/dist')))

// this * route is to serve project on different page routes except root `/`
app.get(/.*/, function (req, res) {
    res.sendFile(path.join(__dirname, '/dist/index.html'))
})

const port = process.env.PORT || 8000
app.listen(port)
console.log(`app is listening on port: ${port}`)

this worked for some minutes (a really few minutes, like 2,3 minutes) but then I get this

2022-12-01T02:38:39.725919+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-12-01T02:38:39.894915+00:00 heroku[web.1]: Process exited with status 143

do you know what could be the problem here or are there any better configuration to deploy a vite app in Heroku? any suggestion? thank you so much

clagccs
  • 2,224
  • 2
  • 21
  • 33
  • I'm working on this same deploy setup today. There's some good info about status 143 exits here: https://stackoverflow.com/questions/15767685/understanding-heroku-server-status-143. I'm assuming you have the heroku/nodejs buildback setup, yeah? – evanmcd Dec 01 '22 at 11:52

1 Answers1

0

You have to create a Procfile on the root of the project with at least this configuration

web: vite preview --port $PORT

As per this recent answer from @hackape.

testing_22
  • 2,340
  • 1
  • 12
  • 28