Vikram Hegde
Vikram Hegde

Reputation: 650

GENERATE_SOURCEMAP=false Issue

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"

Upvotes: 40

Views: 92856

Answers (11)

Najibullah Jafari
Najibullah Jafari

Reputation: 11

In my case it solved by add a set before GENERATE_SOURCEMAP=false and adding && after that, now it looks like this: "start": "set GENERATE_SOURCEMAP=false && react-scripts start" and in build it looks like: "build": "set GENERATE_SOURCEMAP=false && react-scripts build",.

You can edit you script in package.json like this:

"scripts": {
    "start": "set GENERATE_SOURCEMAP=false && react-scripts start",
    "build": "set GENERATE_SOURCEMAP=false  && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start"
},

Upvotes: 0

Ali Zaid
Ali Zaid

Reputation: 286

Source Maps are enabled by default during development. During production builds, they are disabled to prevent you leaking your source on the client, unless you specifically opt-in with the configuration flag. When the productionBrowserSourceMaps option is enabled, the source maps will be output in the same directory as the JavaScript files. Next.js will automatically serve these files when requested. ~nextjs team

NextJs Production Browser SourceMaps

Upvotes: 1

tyler_flx
tyler_flx

Reputation: 101

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

Upvotes: 0

GMKHussain
GMKHussain

Reputation: 4681

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

Linux: GENERATE_SOURCEMAP=false

Windows: set \"GENERATE_SOURCEMAP=false\"

Upvotes: 1

Josh Yager
Josh Yager

Reputation: 361

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

Upvotes: 26

Jenish
Jenish

Reputation: 61

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"

Upvotes: 4

J Olaya
J Olaya

Reputation: 1

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

Upvotes: -3

Alexandru-Dan Pop
Alexandru-Dan Pop

Reputation: 474

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

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

Upvotes: 23

Yuvraj Patil
Yuvraj Patil

Reputation: 8736

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.

Upvotes: 92

Tony
Tony

Reputation: 20102

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

Upvotes: 1

CodeBuggy
CodeBuggy

Reputation: 499

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

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

Upvotes: 17

Related Questions