xCTAPx
xCTAPx

Reputation: 139

How can I start my project from .next folder?

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?

Upvotes: 6

Views: 7148

Answers (2)

Seto
Seto

Reputation: 1686

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.

  1. 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.
  2. You'll need the node_modules folder, package.json, and the lock file.
  3. Then you run pnpm run start from the root of the project. That's where the package.json file is.

Upvotes: 0

SHUVO MUSA
SHUVO MUSA

Reputation: 554

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.

Upvotes: 2

Related Questions