I want to start my NextJS project from build folder (.next). I ran next build
command, got .next folder and... I tried start project from .next folder many times and used a lot of ways, but I wasn't successful. Can anyone explain me what I need to do for starting my NextJS project from build folder?
Can you please mention your package.json
file inside scripts: {}
what was there ?
According to NextJS docs If you run like
If npm then : npm run build
If yarn : yarn build
You will get .next
folder with build files. then you should run npm run start
or yarn start
which will running the project from .next
If you want Static HTML export which slightly different.
Step 1 : open package.json and update this "build": "next build && next export"
inside scripts:{}
and save.
Step 2: Run the build command yarn build or npm run build
it will give you out
folder with static files which you can deploy or run anywhere in your server. Official docs and also npx serve out
for node server.
You don't do that.
But I think I know what you mean because I'm thinking of doing similar thing. I got this working on NextJS 14.2.5, pnpm
, and Node v20.14.0. I think it should work with any package manager that NextJS supported.
- You must build your NextJS application with the
pnpm run build
. This will give you.next
folder. The folder stores the SSG and the SSR part of your website. - You'll need the
node_modules
folder,package.json
, and the lock file. - Then you run
pnpm run start
from the root of the project. That's where thepackage.json
file is.
© 2022 - 2024 — McMap. All rights reserved.