React: ReactPerf throws production is not defined error

Created on 13 Jun 2016  路  1Comment  路  Source: facebook/react

I'm using webpack to build my react project ( "react": "^0.14.6" ), and somehow it is throwing production is not defined ( ReferenceError ) in ReactPerf. Because in my webpack setting, I was injecting the NODE_ENV ( which was working fine before ), any advice on that ?

screen shot 2016-06-13 at 11 11 05 am

screen shot 2016-06-13 at 11 11 05 am

Invalid

Most helpful comment

DefinePlugin just substitutes what you specify as the value. You are specifying 'production', so it embeds the contents of the string (production) in your code, and it blows up. The correct configuration for that key is NODE_ENV: "'production'" (notice the apostrophes inside the quotes!) This way you Webpack will put a JS string in your code, and it will work.

You鈥檒l notice that most example configurations use { NODE_ENV: JSON.stringify('production') }. This is exactly the reason why they鈥檙e doing it. JSON.stringify('production') becomes a string containing "production". But you can specify it in the raw '"production"' or "'production'" form if you鈥檇 like.

TLDR: Replace NODE_ENV: "production" with NODE_ENV: "'production'" in your config.

>All comments

DefinePlugin just substitutes what you specify as the value. You are specifying 'production', so it embeds the contents of the string (production) in your code, and it blows up. The correct configuration for that key is NODE_ENV: "'production'" (notice the apostrophes inside the quotes!) This way you Webpack will put a JS string in your code, and it will work.

You鈥檒l notice that most example configurations use { NODE_ENV: JSON.stringify('production') }. This is exactly the reason why they鈥檙e doing it. JSON.stringify('production') becomes a string containing "production". But you can specify it in the raw '"production"' or "'production'" form if you鈥檇 like.

TLDR: Replace NODE_ENV: "production" with NODE_ENV: "'production'" in your config.

Was this page helpful?
0 / 5 - 0 ratings