36

In windows when I tried to build react app I am getting error saying 'GENERATE_SOURCEMAP' is not recognized as an internal or external command.

I have added below line in my package.json file

"build": "GENERATE_SOURCEMAP=false react-scripts build"
Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
Vikram Hegde
  • 600
  • 1
  • 6
  • 14

9 Answers9

77

Keep this in package.json:

"build": "GENERATE_SOURCEMAP=false react-scripts build",
"winBuild": "set \"GENERATE_SOURCEMAP=false\" && react-scripts build",

Use npm run build for creating build on Linux.

Use npm run winBuild for creating build on Windows.

Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
  • the answer is fine but there is a better solution at https://stackoverflow.com/a/62990101/1909798 – robsonrosa Feb 08 '21 at 16:45
  • 5
    @robsonrosa's comment: "build": "cross-env GENERATE_SOURCEMAP=false react-scripts build" need to install cross-env before using this method. npm install --global cross-env – JM217 Sep 18 '21 at 05:46
  • Do note that in linux you don't need the `&&` part, because in linux it's *a single* command. – Minh Nghĩa Mar 23 '22 at 09:46
23

Another solution is to create a new file in your project's root directory named .env and include the following inside the file. This will remove any .map files from your build/static/js folder the next time you run build.

GENERATE_SOURCEMAP=false
Super Jade
  • 5,609
  • 7
  • 39
  • 61
Josh Yager
  • 331
  • 1
  • 6
19

Use cross-env to safely set environment variables across multiple operating systems:

"build": "cross-env GENERATE_SOURCEMAP=false react-scripts build"

16

Also you can try the below setting in your scripts if you are running on windows

"build": "set \"GENERATE_SOURCEMAP=false\" && react-scripts build"

CodeBuggy
  • 429
  • 5
  • 18
4

For windows

  1. use "set" and
  2. use "&&" in between,

like

"build": "set GENERATE_SOURCEMAP=false && react-scripts build"

,this command also can be used to remove .map files after generated

"build": "react-scripts build && del build/static/js/*.map"
Jenish
  • 61
  • 6
1

maybe something like this would help you, create new app:

npx create-react-app app

cd app

and then run:

GENERATE_SOURCEMAP=false yarn build
aasmpro
  • 554
  • 9
  • 21
Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
1

For Cross Platform: Just open .env and add GENERATE_SOURCEMAP=false

Linux: GENERATE_SOURCEMAP=false

Windows: set \"GENERATE_SOURCEMAP=false\"

GMKHussain
  • 3,342
  • 1
  • 21
  • 19
0

create a file name .env

add this code to the file : GENERATE_SOURCEMAP=false

On Heroku, go to Settings -> Config vars -> add GENERATE_SOURCEMAP with value false

On Vercel, go to Settings -> Environment Variables -> add GENERATE_SOURCEMAP as key and False as value, set environment Production -> Save

tyler_flx
  • 11
  • 1
-3

If you are using Heroku, you have to add this in the Config Vars inside the settings of your App. This is the way is supposed to be set from the documentation documentation