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.
UPDATE 2022-11-23:
See how-to-set-environment-variables-from-within-package-json.
In short:
"start:dev": "NODE_ENV=development next start"
You might need cross-env
(on Windows ? I don't know):
"start:dev": "cross-env NODE_ENV=development next start"
More specific documentation is now available (and maybe requirements also have changed, or maybe not):
environment-variable-load-order:
... Note: The allowed values for NODE_ENV are production, development and test.
... only permitting three (3) values:
- production: When your application is built with next build
- development: When your application is ran with next dev
- test: When your application is being tested (e.g. jest)
ORIGINAL ANSWER:
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 valuesdevelopment
andproduction
. 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 ifprocess.env.NODE_ENV
is not set to production