Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of process.env.NODE_ENV in ES module build #2907

Closed
keanulee opened this issue Mar 28, 2018 · 12 comments
Closed

Remove usage of process.env.NODE_ENV in ES module build #2907

keanulee opened this issue Mar 28, 2018 · 12 comments

Comments

@keanulee
Copy link

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

The ES module build of Redux references process.env.NODE_ENV which doesn't exist on browsers. With unpkg.com's ?module query param that converts package names to paths, this is the only issue blocking users from loading Redux as a module from the browser.

See references to process.env.NODE_ENV in:

What is the expected behavior?

No references to process.env.NODE_ENV in the ES module build.

Demo: http://jsbin.com/tazoliy/edit?html,output

@timdorr
Copy link
Member

timdorr commented Mar 28, 2018

Note that React does this too.

This is important to prevent against the common mistake of including the development checks in a production build, as they significantly impact the speed of Redux. A workable solution would be to check for process's existence first. Can you make a PR for this?

@TimvdLippe
Copy link
Contributor

I see that the corresponding PR has been closed for not being the appropriate solution, but this issue remains. Couls you reopen so we can discuss alternative solutions to resolve this?

@justinfagnani
Copy link

Agreed @TimvdLippe. That Redux modules don't work in the browser without intervention is frustrating. This disrupts otherwise very nice flows like using unpkg.com to serve modules to jsbin and friends.

@markerikson
Copy link
Contributor

Looking at #2910 , it seems that the proposed PR didn't correctly result in the blocks being removed from prod builds. I don't have time to pursue this myself, but if someone can contribute a working solution, we can consider getting it in.

@markerikson markerikson reopened this May 5, 2018
@markerikson
Copy link
Contributor

(Note that the issue being "closed" certainly didn't stop people from being able to discuss this, but I'll re-open it as an indication that it's still a valid topic.)

@TimvdLippe
Copy link
Contributor

TimvdLippe commented Sep 24, 2018

EDIT: As the corresponding PR has been merged, please do not use the below method. Use the officially published Redux package instead

For anyone looking at a browser-compatible ES-module version, I have a PR open in #3143. However, until the Redux maintainers have decided whether or not to merge the PR, you can depend on https://github.com/TimvdLippe/redux/tree/es-browser-build to use the package. Add the following line to your package.json to get the correct version:

"dependencies": {
  "redux": "timvdlippe/redux.git#es-browser-build"
}

@rjcorwin
Copy link

@TimvdLippe Do you have any examples you can point to where this is used? I'm still getting process is not defined using react 4.0.1 and also the package you recommended.

@TimvdLippe
Copy link
Contributor

@rjsteinert You have to point to the es/redux.mjs specifically. You can not just do import "redux" and let that work. E.g. this should work: import { createStore } from "redux/es/redux.mjs";

@rjcorwin
Copy link

@TimvdLippe That did the trick!

@stevesan
Copy link

So, I'm a new user to redux and trying to get it to work with rollup (also karma+jasmine) and I'm running into this multiple times. Is there a clean solution to this, or do we still need to do the replace-hack?

@ghost
Copy link

ghost commented Feb 15, 2021

Hi!

Is using something like import { createStore } from "redux/es/redux.mjs"; still the recommended approach in browsers, and browser based test enivroments (e.g. Karma)?

@justinfagnani
Copy link

Having to import a separate module is not a great solution. Some libraries will do import { createStore } from 'redux/es/redux.mjs'; and others import { createStore } from 'redux';. If you have those both in an app you'll get duplication of the redux library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants