我已经尝试了这里找到的其他解决方案,但没有一个适合我,现在我的启动脚本是这样的
"build": "tsc && vite build",
"start": "vite preview --host 0.0.0.0 --port $PORT",
当我运行这个程序时,我得到这个错误
2022-12-01T02:51:01.843831+00:00 app[web.1]: sh: 1: vite: not found
我将NPM_CONFIG_PRODUCTION
设置为false
,以避免删除devDependencies,因为vite列在那里,但我仍然收到相同的错误
另外,我尝试运行一个静态服务器
"start": "node server.cjs",
我的服务器文件是
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}`)
这工作了几分钟(真的是几分钟,像2,3分钟),但后来我得到了这个
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
你知道什么可能是这里的问题或有任何更好的配置来部署一个vite应用程序在Heroku?任何建议?非常感谢
1条答案
按热度按时间j8yoct9x1#
您必须至少使用此配置在项目的根上创建
Procfile
根据来自@hackape的recent answer。