Skip to content

React 16.0.0-alpha 7 does not bundle correctly in a project using rollup #9361

@pastelsky

Description

@pastelsky

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When using rollup in a project that imports the latest React 16.0.0-alpha7, the bundle ends up containing both react-development.js and react-production.min.js, and the file size is unnecessarily large.

My guess - This happening because the entry point of react was changed recently to

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react.production.min.js');
} else {
  module.exports = require('./cjs/react.development.js');
}

and rollup apparently cannot eliminate exports in dead branches even when replacing process.env.NODE_ENV with production.

Uglify also cannot remove the dead code, because rollup seems to hoist required stuff to the top level.
Online Demo: Try building react@next using this tool that uses rollup to report package sizes. Compare that to searching for just react.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Steps to reproduce:

  1. Import react in any project that uses rollup to bundle.
  2. Use [rollup-plugin-replace] (https://github.com/rollup/rollup-plugin-replace) to replace process.env.NODE_ENV with production.
  3. Use rollup-plugin-node-resolve, rollup-plugin-commonjs and uglifyjs plugins so that rollup understands commonjs exports and minifies stuff.
  4. Check the bundle size, it is 47.5kB.

What is the expected behavior?
Size should be much smaller.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The size is fine when using 15.4.2 because the entry point reads as

'use strict';

module.exports = require('./lib/React');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions