Skip to content

Conversation

@natewallace
Copy link

If the redux module has been bundled outside of webpack and is running on a client browser the process object may not be defined. This pull request adds a check to make sure the process object is ok to use.

@gaearon
Copy link
Contributor

gaearon commented May 17, 2016

If the redux module has been bundled outside of webpack and is running on a client browser the process object may not be defined

The CommonJS build is not intended to be used in browsers. (In fact, there is no way you could run it in a browser because it uses module.exports which also doesn’t exist there.)

The compiled UMD build does not contain process references because it is precompiled. So I don’t see why this would be necessary.

Thanks for the effort though!

@gaearon gaearon closed this May 17, 2016
@natewallace
Copy link
Author

I'm using browserify to bundle the redux code along with some other modules. There is a browserify option that lets you omit builtins like process which trims down the bundle to only module loading support.

My thinking was that by checking for the existence of process the code would be less dependent on the type of module bundler used.

@simplesmiler
Copy link

simplesmiler commented May 18, 2016

@natewallace I believe browserify should be checking browserify.transform field in package.json and applying loose-envify automatically. Does not it do that for you? Maybe you don't have the NODE_ENV environment variable defined?

@natewallace
Copy link
Author

I'm not creating the redux bundle independently but rather I'm pulling redux into a bundle that includes several other modules so I'm not using the browserify configuration found in this project.

I already have a workaround for my scenario but thought my pull request would make the code less dependent on a particular module bundler or its setup.

Just my 2 cents.

@gaearon
Copy link
Contributor

gaearon commented May 18, 2016

The problem with this is it’s a pain to remember and test all possible different configurations. Our advice is simple: if you use CommonJS build, it is up to you to envify it. If you’d rather not, you can use the UMD build as it is.

@gaearon
Copy link
Contributor

gaearon commented May 18, 2016

For the record, this is exactly what React does as well.

@simplesmiler
Copy link

@natewallace when you use redux as a dependency in your project and bundle your project with browserify, it executes the loose-envify transform for redux code, because redux has browserify.transform field and loose-envify dependency specified. You don't need to manually loose-envify unless you are using process.env in your own code. Make sure you have NODE_ENV specified.

@gaearon please correct me if I'm wrong.

@gaearon
Copy link
Contributor

gaearon commented May 18, 2016

@simplesmiler The exception is when you manually tell Browserify not to read local transforms. I think it had some flag for that.

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 this pull request may close these issues.

3 participants