在问这个问题之前,我看了以下问题,但是我相信我是不同的,因为我没有使用Docker:Nextjs无法在生产node_env的'.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时出现此错误。我究竟做错了什么?
然后
解决了我的问题。