Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nextjs - next build with NODE_ENV=development

I'd like to build my nextjs project as development mode.

and I tried like it

package.json

{
  ...
  "scripts": {
    "dev": "next",
    "build:dev": "set NODE_ENV=development & next build",
    "build:prod": "set NODE_ENV=production & next build",
    "start:dev": "set NODE_ENV=development & next start",
    "start:prod": "set NODE_ENV=production & next start"
  }
  ...
}

next.config.js

module.exports = withSass({
  env: {
    baseUrl: process.env.NODE_ENV === "development" ? "devServerURL": "prodServerURL"
  }
});

but I couldn't achieve what I want.

so, I tried with some change.

package.json

  "scripts": {
    "dev": "next",
    "build": "next build",
    "start:dev": "set NODE_ENV=development & next start",
    "start:prod": "set NODE_ENV=production & next start"
  }

but it also doesn't work.

How can I build the next with development mode?

Thanks in advance.

EDIT

My OS is Windows 10.

like image 592
kyun Avatar asked Aug 08 '19 08:08

kyun


Video Answer


1 Answers

See issue #9123, (Oct 18, 2019) :

NODE_ENV is a reserved environment variable that cannot be changed. The only valid values are production, development, and test.

If you need your app behavior to change in different production environments, please use a different variable like APP_ENV.

And issues #17032 (Sep 12, 2020):

process.env.NODE_ENV only has 2 possible values development and production. If this is not set to that value you'll run into all kinds of library edge cases (especially in node_modules) where you get severely de-optimized results. E.g. if you run a performance test you'll get significantly worse results if process.env.NODE_ENV is not set to production

like image 70
kca Avatar answered Oct 19 '22 23:10

kca