![](/img/trans.png)
[英]How does “npm run build” run the scripts in jquery github repo?
[英]Unable to deploy node app to Heroku thru Github - does not run npm build
我有一個項目,我試圖通過 github 上的源文件在 Heroku 上部署該項目,但它無法“構建”該項目,而是運行 npm start (據我所知)。
這是我的 package.json 文件:
{
"name": "workout-app",
"version": "1.0.0",
"description": "Work out builder",
"main": "index.js",
"scripts": {
"dev": "webpack-dev-server",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open",
"start-dev": "npm run build",
"heroku-postbuild": "webpack -p && node server.js"
},
"author": "Levon Saiyan",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.11.5",
"babel-loader": "^8.1.0",
"core-js": "^3.6.5",
"html-webpack-plugin": "^4.5.0",
"install": "^0.13.0",
"npm": "^6.14.8",
"regenerator-runtime": "^0.13.7",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"axios": "^0.21.0",
"babel-polyfill": "^6.26.0"
}
}
這是 server.js 文件:
const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname + '/dist'));
// send the user to index html page inspite of the url
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'index.html'));
});
app.listen(port);
在heroku上,這是我得到的錯誤:
2020-11-09T17:52:31.135227+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=newnameworkout.herokuapp.com request_id=83df8e1d-d909-4b97-a768-f03297b67c71 fwd="136.34.60.0" dyno= connect= service= status=503 bytes= protocol=https
我已經在網上查看了所有內容並嘗試了所有內容,但我總是收到此錯誤。 我究竟做錯了什么?
查看您的 package.json,看起來您已經在 devDependencis 中導入了所有依賴項。 嘗試將其移動到依賴項下。
如果那沒有幫助,請嘗試使用 Procfile(如果您沒有使用過)。
在應用程序的根目錄中創建一個名為 Procfile 的文件,沒有任何文件擴展名。
開始:節點 server.js
在 Procfile 中輸入以上行並嘗試通過 github 在 Heroku 中部署您的應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.