How can I start my project from .next folder?
Asked Answered
E

2

6

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?

Expedite answered 14/9, 2020 at 15:6 Comment(4)
next build && next start nextjs.org/docsNikolos
It doesn't work if I do it from .next directory because I get error that next not found.Expedite
It's not meant to be executed from the .next directory, run it from the project rootEcotone
But I need deploy this project. For this purpose I need start my project from any folder separate from project root directory.Expedite
C
2

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.

Casares answered 15/9, 2020 at 9:46 Comment(2)
I know about everything you mentioned. But I got .next folder and further I want to move it to e.g. desktop and run from desktop (if .next is analog build folder it must work), but it doesn't work. How can I deploy my .next (not Vercel, but my nginx web-server)?Expedite
this did not answer the question. you want to move dir to desktop as you said it and run in there for example. i did not came across any answer that resolves this. questionCompressor
R
0

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.
Raimes answered 15/10 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.