preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
950 stars 148 forks source link

Fix DEV always being false in webpack #504

Closed marvinhagemeister closed 5 years ago

marvinhagemeister commented 5 years ago

Found this while debugging why prop-types didn't work in preact-cli (see: https://github.com/developit/preact-cli/issues/627).

Turns out the reason is that our global DEV variable was always set to false when preact-compat was bundled. The reason being that we checked if process is available:

const DEV = typeof process !== 'undefined' && process.env && process.env.NODE_ENV!=='production';

But bundlers typically don't shim the process object and instead replace all string occurrences of process.env.NODE_ENV with development for example. After the bundler has done its magic the code would now look like this:

const DEV = typeof process !== 'undefined' && process.env && 'development'!=='production';

Note that process is still undefined which is why DEV will always be false.

developit commented 5 years ago

released in 3.18.4!