Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  191] [ 4]  / answers: 1 / hits: 73572  / 9 Years ago, tue, march 17, 2015, 12:00:00

I'm trying to run the hot dev server on our site with webpack; the site uses ReactJS, which has this code in it:



if (production !== process.env.NODE_ENV) // etc


When not running hot-swap it's fine, but with the hot-swap, it gets run, resulting in the error:



TypeError: process.env is undefined


The code looks like this:



error



The project is modelled after https://github.com/webpack/react-starter which does work; so the question is; what error have I made in the config file and/or how do I go about looking for the error when the 'production' compilation works just fine?



I've posted the gist of the webpack config file.


More From » reactjs

 Answers
161

In your webpack config, there are two options that can affect process.env:





Looking at your code, it looks like process.env might be undefined when both options.prerender and options.minimize are false.



You could fix this by always using an environment that defines process.env (ex: node), or by using DefinePlugin to assign a default value to the variable yourself.


[#67410] Saturday, March 14, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brandt

Total Points: 43
Total Questions: 90
Total Answers: 111

Location: Aruba
Member since Fri, Jun 24, 2022
2 Years ago
brandt questions
Sun, Jul 4, 21, 00:00, 3 Years ago
Wed, Jun 30, 21, 00:00, 3 Years ago
Sat, Jan 23, 21, 00:00, 3 Years ago
Mon, Sep 21, 20, 00:00, 4 Years ago
;