Reputation: 1305
My 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"
}
}
Below is the error log.
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)
While running npm start it is display error inside node_modules/next-server/dist/server/next-server.js
Upvotes: 1
Views: 378
Reputation: 5840
Run npm run build
first. When you run npm run start
, it's trying to start a local server so you can run your app locally. But if you just installed it and haven't yet built your app (as the error indicates), your local server doesn't have anything to serve up.
If you want to run it locally while you're developing (ie, with live reloading), use npm run dev
.
Upvotes: 1