6

I need to build My React NextJS Project on local to host it at Appache server, when I run command run build it did not generate build folder.

I R & D on it, everyone recommend ZEIT – Next.js build with Now but it build project on cloud but I need a build for my local appache server. So please help me out.

Here is an my of package.json:

......
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start"
},
......

2 Answers 2

4

After so many struggle, I found answer of my question I have to add following line in my package.json under scripts:

"scripts": {
    ......
    "export": "npm run build && next export"
    .....
},

Basically I my case, npm run build && next export was complete required command to build NextJS project. So after adding this into package.json you just need to run in terminal: npm export and it will generate complete build for nextjs project.

Sign up to request clarification or add additional context in comments.

1 Comment

This only works if your app isn't creating any dynamic pages at runtime.
-1

You have a package.json script called build that runs next build. The next build command by default builds the app for development, which doesn't create a production bundle.

In order to create the production bundle on your local machine, you need to specify that you're on production environment through NODE_ENV=production (this is done automatically in now and other deployment servers). Basically, your package.json would end up:

"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start",
"prod:build": "NODE_ENV=production npm run build"
},

You can replace npm run build with next build directly if you prefer that.

1 Comment

Does not create a build folder on next v7.0.2 for me. Do you know another method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.