"Uncaught ReferenceError: process is not defined" and the solution

The Uncaught ReferenceError: process is not defined happens when when a non-existent (here: process) variable is referenced.

Most likely the problematic code snippet looks like:


var isProduction = process.env.NODE_ENV === 'production';    

The process.env property is available on node, but not in the browser which causes the above error.

To fix the problem, define the variable pro-actively before the library is loaded, e.g.:


window.process = {
    env: {
        NODE_ENV: 'development'
    }
}    

The fix/script can be loaded with e.g.:

<script src="init.js"></script>

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License