vert-x3 / vertx-lang-js

Nashorn JavaScript implementation for Vert.x
Apache License 2.0
35 stars 23 forks source link

Make process.env.NODE_ENV available #10

Closed tbo closed 9 years ago

tbo commented 9 years ago

A lot of popular npm packages (i.e. react, superagent) are accessing process.env.NODE_ENV in order to deduce if and how they should handle debugging related tasks. Apparently you are using jvm-npm. Based on my experience with vert.x 2, it would suffice to define process.env before loading jvm-npm. In vert.x 2 it would look like this:

 var process = {env: {}};
 load('./jvm-npm.js');
 var React = require('react');

It would probably be even better, if we could read out the actual value of NODE_ENV. But the API for accessing environment variables was changed and the new one is not documented yet.

aesteve commented 9 years ago

Totally +1.

I'm currently testing to render react components on server-side and when I require react I got the error that process is undefined or cannot read property NODE_ENV of undefined.

It's a pretty easy fix and could even be injected through an API (setNodeEnv, or something like that).

purplefox commented 9 years ago

We could certainly add this, but unless react is specifically designed to only run on Node.js then I'd consider this a bug in react. Have you tried submitting a bug report with them?

purplefox commented 9 years ago

I've added process.env anyway so as not to block you :)

aesteve commented 9 years ago

Thanks alot Tim.

In fact I think it's a matter of what is under the scope of "pure" npm (if it even makes sense) dependency and node-dependency.

The react I'm trying to require has been installed under node-modules, so I think it's logical the module is expecting a node environment.

Anyway, thanks, we'll be able to use node modules which is really interesting.