【发布时间】:2018-11-29 12:54:52
【问题描述】:
在问这个问题之前,我查看了以下问题,但我相信我的问题不同,因为我没有使用 Docker:Nextjs fails to find valid build in the '.next' directory in production node_env
我也尝试了this 删除“.next”文件夹的方法,但仍然遇到同样的问题。
在解决了许多其他问题之后,我发现了一个我似乎无法解决的问题。当我尝试部署到 Heroku 时,我不断收到以下错误:
node server.js
Could not find a valid build in the '.next' directory! Try building your app with 'next build' before starting the server.
这是我的 package.json 文件:
{
"name": "StarterApp",
"version": "1.0.0",
"engines": {
"node": "10.4.1"
},
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha",
"dev": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "4.16.3",
"fs-extra": "^5.0.0",
"ganache-cli": "^6.1.3",
"mocha": "^5.2.0",
"next": "^4.2.3",
"next-routes": "^1.4.2",
"node-gyp": "^3.7.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"rebuild": "^0.1.2",
"semantic-ui-css": "^2.3.2",
"semantic-ui-react": "^0.79.1",
"sha3": "^1.2.2",
"solc": "^0.4.24",
"truffle-hdwallet-provider": "0.0.3",
"web3": "^1.0.0-beta.34"
}
}
Server.js 文件:
const { createServer } = require('http');
const next = require('next');
const app = next({
dev: process.env.NODE_ENV !== 'production'
});
const routes = require('./routes');
const handler = routes.getRequestHandler(app);
app.prepare().then(() => {
createServer(handler).listen(5000, (err) => {
if (err) throw err;
console.log('Ready on localhost:5000');
});
});
应用程序在本地部署没有问题,但在部署到 Heroku 时出现此错误。我究竟做错了什么?
【问题讨论】:
-
您必须先创建一个构建。在“npm start”之前运行“next build”
-
嘿!我的服务器文件看起来相同。你没碰巧上过 Stephen Griders Ethereum/Solidity 课程吧?如果是这样,我有一些编译/部署的自动化,你应该检查一下。
-
@NikHammer-Ellis 抱歉耽搁了这么久!不知怎的错过了这个!我在哪里可以查看?谢谢!