hybrids: bundlers: process.env.NODE_ENV in rollup breaks build

I have created a repo for demo : https://github.com/vogloblinsky/hybrids-build-rollup

After building the main js file, i got this error in the html page :

Uncaught ReferenceError: process is not defined

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

The problem with process.env.NODE_ENV is solved in last v2.0.0 release. It is a simple trick to check if that object exists. It also doesn’t break minification feature where the code is replaced with a string value.

try { process.env.NODE_ENV } catch(e) { var process = { env: { NODE_ENV: 'production' } }; }

The line is removed for production usage with bundlers. Those which does not support that feature, it still works, by fallback to ‘production’ value (in the catch block).

For now, the dist/hybrids.js built version is already minified with "production" value. Other targets - lib/index.js and esm/index.js are not minified and relay on process.env.NODE_ENV value with fallback, if it is not set.

Yes i will do a new issue for discussing