gpt4 book ai didi

node.js - NextJS 在 '.next' 目录中找不到有效的构建

转载 作者:搜寻专家 更新时间:2023-10-31 22:53:35 25 4
gpt4 key购买 nike

在问这个问题之前,我查看了以下问题,但我相信我的问题有所不同,因为我没有使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com