在问这个问题之前,我看了以下问题,但我相信我是不同的,因为我没有使用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 run build
然后
npm run start
解决了我的问题。
关于node.js - NextJS在 '.next'目录中找不到有效的内部版本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50947389/