ΩmegaMan
ΩmegaMan

Reputation: 31686

NPM Run Build Always Builds Production and Never Development

On an inherited project I have, I am trying to get the build command to build a version other than Production.

I have attempted to change the alias in the script section in package.json to pass in extra variables such as --dev and --configuration=dev to no avail.


The project has these json data files:

 env.dev
 env.development
 env.production

with the package.json has this build alias build:dev which I run npm run build:dev:

"scripts": {
    "start": "NODE_ENV=dev && react-scripts start",
    …
    "build:dev": "npm run build --dev --configuration=dev && react-scripts build"
}

This works and builds, but for production only which I verify when I view the resultant files.


If I remove the file env.production from the directory and run the build command, it fails with:

Creating an optimized production build...
Failed to compile.

Module not found: Error: Can't resolve 'polyfills' in 'C:\Work\MyProj\WebSiteName\src'

which just informs me that it can alias polyfills found in the env.production file for the location NODE_PATH=src/.

Thoughts?

Upvotes: 16

Views: 41553

Answers (1)

Michael
Michael

Reputation: 5048

you need to set the env. variable like you do in "start" before calling the build command.

"build:dev": "NODE_ENV=dev npm run build --dev --configuration=dev && react-scripts build"

Upvotes: 6

Related Questions