【发布时间】:2018-04-22 06:21:09
【问题描述】:
我正在使用 React & NodeJS 和 yarn 包管理器。我的应用程序在本地运行良好。但是当我将它上传到 Heroku 时,它显示无法获取 /
加载资源失败:服务器响应状态为 404(未找到)
我的 webpack.config.prod.js 文件看起来像这样
const JS_BUNDLE = 'bundle.js';
module.exports = function (paths, loaders, plugins) {
return {
output: {
path: paths.dist,
filename: JS_BUNDLE,
},
module: {
rules: [
loaders.style,
],
},
devtool: 'source-map',
plugins: [
plugins.loaderOptions({
minimize: true,
}),
plugins.uglifyJs({
output: {
comments: false,
},
compress: {
warnings: false,
drop_console: true,
dead_code: true,
unused: true,
conditionals: true,
comparisons: true,
sequences: true,
evaluate: true,
if_return: true,
join_vars: true,
},
}),
plugins.definePlugin,
plugins.genHtml({
filename: 'index.html',
template: 'template.html',
}),
],
};
};
我相信它在 package.json 上运行 yarn 和我的脚本时不会创建 index.html
"scripts": {
"watch-dev": "NODE_ENV=development webpack-dev-server --hot --inline",
"api": "PORT=3000 nodemon server.js",
"start": "node server.js"
}
Heroku 日志
2017-11-09T09:31:46.907824+00:00 heroku[web.1]:状态从开始变为向上
2017-11-09T09:31:48.165220+00:00 应用[web.1]:GET / 404 139 - 55.164 毫秒
2017-11-09T09:31:48.154963+00:00 heroku[路由器]: at=info method=GET path="/" host=hksmetal.herokuapp.com request_id=0692c07a-6f96-4708-8a74-30704fbad48e fwd="213.247.123.26" dyno=web.1 connect=1ms service=128ms status=404 bytes=543 protocol=https
如果有任何建议,请提前感谢
【问题讨论】:
-
请从应用程序的heroku终端发布日志..
-
是的!我的错误我已经添加了
标签: node.js reactjs heroku npm yarnpkg