我正在使用常规设置在Heroku上部署Node.js:
webpack.config.common.js
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const port = (process.env.PORT || 8000);
console.log('========================= process.env.PORT')
console.log('port')
console.log(port)
module.exports = {
entry: {
app: './src/index.js',
vendor: [
'react',
'react-dom'
]
},
resolve: {
modules: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules')
],
extensions: [
'.js', '.jsx'
]
},
output: {
path: path.resolve(__dirname, 'build')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [ 'babel-loader' ]
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'React Application',
template: 'public/index.html'
}),
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor' }),
new webpack.optimize.CommonsChunkPlugin({ name: 'runtime' }),
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.ModuleConcatenationPlugin()
],
devServer: {
inline:true,
port: port
}
}
但是Heroku日志告诉您端口已设置并且所有编译都成功,但是在启动后却出现2个错误:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Error H10 "App crashed"
完整日志:
2018-07-02T15:26:04.990004+00:00 app[web.1]: =========================
2018-07-02T15:26:04.991913+00:00 app[web.1]: port
2018-07-02T15:26:04.991966+00:00 app[web.1]: 55112
...
2018-07-02T15:26:05.268729+00:00 app[web.1]: Project is running at http://localhost:55112/
...
2018-07-02T15:26:19.533902+00:00 app[web.1]: webpack: Compiled successfully.
...
2018-07-02T15:26:56.959328+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=task-manager-ui.herokuapp.com request_id=8e8a2f10-cfad-420c-81d3-fa9a79552c7d fwd="95.134.31.126" dyno= connect= service= status=503 bytes= protocol=https
2018-07-02T15:27:01.090609+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-07-02T15:27:01.090792+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-07-02T15:27:01.193039+00:00 heroku[web.1]: Process exited with status 137
2018-07-02T15:27:01.348451+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-02T15:27:02.978159+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=task-manager-ui.herokuapp.com request_id=31c2da3b-de7f-4dc8-86ab-05177e2f8674 fwd="95.134.31.126" dyno= connect= service= status=503 bytes= protocol=https
2018-07-02T15:27:04.630907+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=task-manager-ui.herokuapp.com request_id=efd82add-0ba0-4fc8-8065-826900c616af fwd="95.134.31.126" dyno= connect= service= status=503 bytes= protocol=https
如何使用正确的Node.js配置设置Heroku?