我的Package.js
{
"name": "nextjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build",
"prod_start": "NODE_ENV=production node server.js",
"start": "next start"
},
"author": "",
"license": "ISC",
"dependencies": {
"next": "^9.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}
下面是错误日志。
Error: Could not find a valid build in the 'xxx/nextjs/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (xxx/node_modules/next-server/dist/server/next-server.js:425:23)
at new Server (xxx/node_modules/next-server/dist/server/next-server.js:43:29)
at module.exports (xxx/node_modules/next-server/index.js:4:10)
at module.exports.options (xxx/node_modules/next/dist/server/next.js:2:161)
at start (xxx/node_modules/next/dist/server/lib/start-server.js:1:385)
at nextStart (xxx/node_modules/next/dist/cli/next-start.js:22:125)
at commands.(anonymous function).then.exec (xxx/node_modules/next/dist/bin/next:29:346)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
运行npm时,在node_modules / next-server / dist / server / next-server.js中显示错误
答案 0 :(得分:1)
首先运行npm run build
。当您运行npm run start
时,它将尝试启动本地服务器,以便您可以在本地运行应用程序。但是,如果您只是安装了它而尚未构建您的应用程序(错误指示),那么您的本地服务器将无法提供任何服务。
如果您要在开发过程中( )在本地运行(即实时重新加载),请使用npm run dev
。