GENERATE_SOURCEMAP=false does nothing in a Create React App build on Windows
GENERATE_SOURCEMAP=false in a package.json script has no effect on a Windows machineShort answer
GENERATE_SOURCEMAP is an environment variable that react-scripts reads for production builds only. The Linux form VAR=value command does not work in Windows cmd or PowerShell. Put the variable in a .env file, or set it with the syntax of your shell, or through cross-env, then run npm run build again.
Fix it fast
1Find out which cause you have
Build, then count the source map files. If any .map file exists, the variable did not reach react-scripts.
npm run build dir /s /b build\static\*.map2Match what you see, then jump to its fix
- 1
The script is written as GENERATE_SOURCEMAP=false react-scripts buildThe Linux inline syntax is used in cmd or PowerShellFix - 2
The value works in one terminal and not in another, or in CIThe variable has to live in a .env fileFix - 3
You expect fewer source maps while running npm startThe variable is only used for production buildsFix - 4
The same package.json is used on Windows and Linux machinesYou need one npm script that works on every operating systemFix
- 1
What does the error look like?
GENERATE_SOURCEMAP=false in a package.json script has no effect on a Windows machineSource map (.map) files are still created in build/static after setting GENERATE_SOURCEMAP=false
Cause 1 of 4
The Linux inline syntax is used in cmd or PowerShell
1Check
The VAR=value command form is Bash syntax. Windows cmd and PowerShell use their own forms.
findstr GENERATE_SOURCEMAP package.json2Fix
Use the syntax of your shell. In cmd keep the quotes around the assignment, because they avoid a trailing space in the value.
:: cmd.exe
set "GENERATE_SOURCEMAP=false" && npm run build
# PowerShell
($env:GENERATE_SOURCEMAP = "false") -and (npm run build)3Verify
Build again and check that no .map files are listed.
dir /s /b build\static\*.mapConfirmed by create-react-app.dev
Cause 2 of 4
The variable has to live in a .env file
1Check
The docs say you can set these variables in your shell or in .env. A .env file in the project root is read the same way on every operating system.
type .env2Fix
Create a .env file in the project root (next to package.json) with the line below. Restart any running dev server after editing it.
GENERATE_SOURCEMAP=false3Verify
Run the production build and check build/static for .map files.
npm run buildConfirmed by create-react-app.dev
Cause 3 of 4
The variable is only used for production builds
1Check
In the Create React App settings table GENERATE_SOURCEMAP is ignored in development and used in production.
npm run build2Fix
Set it for npm run build. The development server is not affected by it, so it does not need the variable.
# .env.production
GENERATE_SOURCEMAP=false3Verify
A production build should no longer write .map files.
npm run buildConfirmed by create-react-app.dev
Cause 4 of 4
You need one npm script that works on every operating system
1Check
The cross-env README explains that most Windows command prompts do not accept the VAR=value form, and that Windows uses a different variable syntax.
npm ls cross-env2Fix
Install cross-env and put it in front of the command in the script. The project is in maintenance mode and its repository is archived, so a .env file is the simpler long-term choice.
npm install --save-dev cross-env
"scripts": {
"build": "cross-env GENERATE_SOURCEMAP=false react-scripts build"
}3Verify
Run npm run build on both systems.
npm run buildConfirmed by github.com
How do I stop it coming back?
- Prefer a committed .env.production for settings the whole team needs.
- Remember the variable affects builds only; do not expect it to change npm start.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix