[英]Problem deploying Rails 3.1 project to Heroku: Could not find a JavaScript runtime
[英]Problem with deploying frontend to heroku
我有一個具有這種結構的 typeorm 項目:
在客戶端和根目錄中,索引文件都位於 src 目錄中。 在客戶端目錄中的 package.json 中,我更改了一件事(“構建”)並添加了代理:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && mv build ../public",
"test": "react-scripts test",
"eject": "react-scripts eject",
"gen": "graphql-codegen --config codegen.yml"
},
"proxy": "http://localhost:4000"
在 src/index.ts 我做到了:
const app = express();
...
app.get("/", (_req, res) => res.send("hello"));
app.use(express.static('../public'));
app.get('*', (_, res) => {
res.sendFile(path.resolve(__dirname, '../public', 'index.html'))
});
const port = process.env.PORT || 4000;
app.listen(port, () => console.log(`Server started on port ${port}`));
以及來自根目錄的 package.json 的一部分:
...
"scripts": {
"start": "ts-node src/index.ts",
"server": "nodemon --exec ts-node src/index.ts",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
}
當我在本地主機上運行它時它可以工作,但是當我部署在 heroku 上時,它向我展示了我在后端(在端口 4000 上)得到的,就是這個“你好”。
好的,很好。 我剛剛將無效路徑傳遞給 espress.static:
app.use(express.static('public'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.