45

I have React js installed via NPM and using browserify to manage components in react. When an exception occurs in React, the console shows as

"Uncaught Error: Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings."

How do I enable full error messages ?

Raathigesh
  • 2,306
  • 3
  • 26
  • 32
  • 2
    Well, it's telling you, "use the non-minified dev environment for the full error message and additional helpful warnings." – Benjamin Gruenbaum Apr 12 '15 at 07:08
  • I'm not referencing the React Js file directly in my source. I'm requiring react through browserify like var React = require('react'); How do I configure browserify to use the non-minified version ? – Raathigesh Apr 12 '15 at 07:11
  • 2
    This is literally in the first page of the documentation about using react with browserify - is your `NODE_ENV` set to `production`? – Benjamin Gruenbaum Apr 12 '15 at 07:12
  • Setting the environment variable to 'development' resolved the issue. Thanks a lot Benjamin Gruenbaum for the quick response :) – Raathigesh Apr 12 '15 at 07:26
  • 1
    You're very welcome, now I _could_ write an answer but I think there would be better value in you writing the answer ala Q&A style. – Benjamin Gruenbaum Apr 12 '15 at 07:31
  • 9
    Better question: why can't the minified exception have a stack trace? It's a pretty big problem when no exception is occuring in dev mode... – Andy Sep 16 '15 at 00:02
  • @Andy: I thought that building the stacktrace is a pretty expensive operation so it's simply skipped for production. But yeah, I've got the same problem here... The bug does not occur in the dev version ;) – Laoujin Apr 14 '16 at 12:12
  • @Laoujin interesting point! Looks like a lot of people want a separate option to turn production error messages on/off: https://github.com/facebook/react/issues/2686 – Andy Apr 14 '16 at 15:28
  • https://twitter.com/dan_abramov/status/748969886433546240 – Raathigesh Jul 02 '16 at 04:29
  • 2
    I execute set NODE_ENV=development&& node app.js from my package.json and still only get minified errors :( – Killroy Sep 13 '16 at 15:04
  • i have a question, i am not using React at all and i am still getting this error. I dont even have npm installed on my server. why i am getting this error? – Dimitar Jun 28 '18 at 10:24

12 Answers12

37

Setting NODE_ENV to development as Benjamin Gruenbaum pointed out in the comment resolved the issues.

set NODE_ENV=development
Raathigesh
  • 2,306
  • 3
  • 26
  • 32
  • In gulpfile I do `process.env.NODE_ENV = 'development'` but still get generic message?? – Labithiotis May 13 '15 at 21:15
  • Could you try executing `set NODE_ENV=development` in the command prompt and see ? – Raathigesh May 14 '15 at 17:23
  • I wrote this on the command prompt in the project's base directory. However, it seems to have no effect.(I am using Windows 7) – bsky Nov 13 '15 at 09:59
  • 2
    [Other ways to switch React to dev mode](http://stackoverflow.com/questions/22118915/how-to-turn-on-off-reactjs-development-mode) in case this one doesn't work for you. – Roman Starkov Apr 14 '16 at 14:02
  • 26
    "WTF why am I getting this error?" let me take a quick look at StackOverflow - oh snap - I answered it in the comments. Story of my life -_- – Benjamin Gruenbaum Jun 14 '16 at 12:23
  • Also if you've packaged with webpack/browserify in production mode changing this later won't help you out; you'll need to recompile in development mode. – El Yobo Jul 01 '16 at 08:42
16

If you are encountering this issue with Karma + Webpack, the following Webpack configuration fixed the issue for me when running tests:

plugins: [
    new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: JSON.stringify('development')
        }
    })
]
Jackson
  • 9,188
  • 6
  • 52
  • 77
14

I FINALLY SOLVED THIS.

If you're like me and ran that command to set NODE_ENV and it's literally never worked, check if you're linking to react.min.js instead of the full versions of the files.

Link to the full versions and it should work like a charm. :D

davidawad
  • 1,023
  • 11
  • 20
  • 1
    Would you mind explaining what you did to link to the full version? Did you `require('./node_modules/react/dist/react.js')`? – kevin628 Jan 25 '16 at 04:37
  • in your html using the script tag src attribute, I wasn't linking to the full version, I was using the production version. This was before I understood how to use bower so I wasn't understanding the difference. – davidawad Jan 25 '16 at 06:02
7

If you are using jspm to bundle your code, note that version 0.16.24 imports the minified "production" version of React, which throws this error. My temporary solution was to downgrade jspm to 0.16.23.

edit Future versions of jspm will allow you to declare production vs. development versions (see jspm beta documentation)

chas
  • 407
  • 4
  • 6
5

I had this issue, and for me I didn't need to disable minification or use react source. My script was just loading before the root element. So I just moved the script out of the head and below the div in the index file source code and that fixed it.

Changed my index.jade from this:

html
 head
   title Super coo site
   script(src="bundle.js")
 body
   div#root

To this:

html
 head
   title Super coo site
 body
   div#root
   script(src="bundle.js")
Grant Eagon
  • 1,400
  • 1
  • 12
  • 24
2

I got this error when my render method returned undefined eg

render() {
    let view;
    // Not paying attention and slip a case where view won't get assigned a value
    if(this.props.foo == 'hello') {
        view = <HelloView />
    }
    else if(this.props.foo == 'bye') {
        view = <ByeView />
    }
    return view;
}

This will trigger the error when this.props.foo is 'hi'

roelkok
  • 337
  • 1
  • 6
  • 1
    This is true, check if you use some variable in the render function that isn't created yet or undefined, it's really misleading error message but this works for me – medhatdawoud Apr 09 '17 at 17:40
2

Have you check the DOM element that you are trying render ? I had this error before due to a silly mistake. The worst part is bundle was minified. The element id is not same

Index.html

<div id="ds-app"></div>

app.jsx

React.DOM.render(<App/>, document.getElementById('app'))
ravibagul91
  • 20,072
  • 5
  • 36
  • 59
Terry
  • 1,470
  • 13
  • 15
0

As of version 15.2, production React error messages (NODE_ENV=production) now include a URL that you can visit where you can see the original, unobfuscated error.

https://twitter.com/dan_abramov/status/748969886433546240

You should consider upgrading to React 15.2 in order to get access to these error messages. Additionally, some production crash reporting tools automatically unminify these errors for you.

Ben Vinegar
  • 307
  • 1
  • 8
  • 1
    It's important to point out, for this answer, that he's speaking specifically about error messages _in production mode_, for which this point is indeed relevant. – KendallB Aug 21 '17 at 19:30
0

use the min.js files in production or bundle your application code with process.env.NODE_ENV === 'production' and you should be good to go!

vimuth
  • 5,064
  • 33
  • 79
  • 116
Vithu Jey
  • 13
  • 3
0

If your package.json scripts has dll, try exec npm run dll or yarn run dll.

fenghen
  • 66
  • 1
  • 3
0

I am developing my first Shopify app and using heroku to host it. Nothing worked for me until I discovered this topic and one other. Here is my vite.config.js:

import react from "@vitejs/plugin-react";
import "dotenv/config";

/**
 * @type {import('vite').UserConfig}
 */
export default {
    define: {
        "process.env.SHOPIFY_API_KEY": JSON.stringify(process.env.SHOPIFY_API_KEY),
        "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
    },
    //plugins: [react()],
    plugins: [
        process.env.NODE_ENV !== `production` ? react({
            jsxRuntime: `classic`,
        }) : react(),
    ],
};

NODE_ENV=development

I hope this helps someone

Chris
  • 650
  • 7
  • 20
0

In my case, it was because of package-lock.json. Delete and redeploy