question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiled apps use development version of react and react-dom

See original GitHub issue

Prerequisites

  • Using yarn
  • Using node 10.x
  • Using an up-to-date master branch
  • Using latest version of devtools. See wiki for howto update
  • Link to stacktrace in a Gist (for bugs)
  • For issue in production release, devtools output of DEBUG_PROD=true yarn build && yarn start
  • Tried solutions mentioned in #400

Expected Behavior

An app created with yarn package will use react.production.min.js and react-dom.production.min.js

Current Behavior

An app created with yarn package, in vanilla git clone’s of both the master and the next branch, ships with react.development.js and react-dom.development.js, see screenshot below.

screenshot 2019-02-07 at 23 07 38

Possible Solution

Not found any yet, but I assume NODE_ENV gets overwritten or unset somewhere.

Steps to Reproduce (for bugs)

  1. fresh checkout of the repo
  2. yarn
  3. yarn run package
  4. inspect the sources of the app

Context

A compiled app should be as fast as possible, running the production version of react is very important in that context.

Your Environment

  • Node version : 10
  • Version or Branch used : master as well as next
  • Operating System and version : mac os mojave

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kiliancommented, Feb 13, 2019

yarn start runs electron with NODE_ENV=production prefixed, which is why that does work (though there is a comment there on lacking dead code elimination?)

Thanks for the plugin above! It’s not ideal but it gets the job done! 👍

1reaction
barretroncommented, Feb 12, 2019

I can reproduce it using @Kilian 's test after running yarn package (I was using yarn start before, which doesn’t package the app).

Here’s what seems to work for me so far:

Add the following snippet to plugins in the prod webpack configs:

  • configs/webpack.config.main.prod.babel.js
  • configs/webpack.config.renderer.prod.babel.js
    /**
     * Set NODE_ENV to "production" for external dependencies
     *
     * Note: this is required for both main and renderer
     * separately since the renderer process doesn't inherit
     * the main process's environment on Linux.
     */
    new webpack.BannerPlugin({
      banner: 'process.env.NODE_ENV="production";',
      raw: true,
      entryOnly: true,
      test: /\.js$/
    })

🤷‍♂️ kind of hacky but guarantees that the environment will be set prior to any require statements running

Read more comments on GitHub >

github_iconTop Results From Across the Web

CDN Links - React
Both React and ReactDOM are available over a CDN. ... The versions above are only meant for development, and are not suitable for...
Read more >
Create a New React App
Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in...
Read more >
ReactDOM – React
ReactDOM. The react-dom package provides DOM-specific methods that can be used at the top level of your app and as an escape hatch...
Read more >
React v16.0 – React Blog
We're excited to announce the release of React v16.0! Among the changes are some long-standing feature requests, including fragments, ...
Read more >
Optimizing Performance - React
It is expected that you use the development mode when working on your app, ... We offer production-ready versions of React and React...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found