cloudfoundry-community / node-cfenv

easy access to your Cloud Foundry application environment for node
Apache License 2.0
74 stars 20 forks source link

Process is not defined error #27

Closed tortilaman closed 4 years ago

tortilaman commented 7 years ago

This error only pops up when I include the cfenv package. As soon as I import it (I'm using webpack) I get the below trace:

    at getPortsFile (index.js?83c6:59)
    at eval (index.js?83c6:13)
    at Object.<anonymous> (bundle.js:3915)
    at __webpack_require__ (bundle.js:660)
    at fn (bundle.js:86)
    at Object.eval (cfenv.js?376b:13)
    at eval (cfenv.js?376b:282)
    at Object.<anonymous> (bundle.js:3738)
    at __webpack_require__ (bundle.js:660)
    at fn (bundle.js:86)

It's possible the problem is with the ports package or something else, but at this point I'm just using a .env file because I can't figure this out. It would be nice to be able to use this package though, as it would simplify changes down the line.

pmuellr commented 7 years ago

As soon as I import it (I'm using webpack) I get the below trace

Where do you get the trace? When you're running a node app, building a webpack archive, using a webpack archive in a browser? etc ... It smells like you're running in a browser since you're using webpack.

cfenv is a library that parses environment variables in a node environment (eg, properties in process.env), and then gives you some objects/functions that make it easier to access the data in those environment variables.

I'm not sure what the use would be from a browser, but I guess it's possible if you somehow can create an equivalent node environment in a browser; eg, a global process object that has a property env with env var/value properties. It looks like your environment is not set up to do that, if something is complaining about "Process is not defined".

Even if you got as far as creating a node-like env with process.env, the code currently does call some other node packages to get default port values. I suspect those won't work in a browser, but who knows! Not out of the question that cfenv could sense whether it was running in a browser and avoid usage of those other node packages, with some loss of functionality.

But I'm hard-pressed to come up with a rationale for a real use case of using cfenv in a browser to begin with.

pmuellr commented 4 years ago

closing as it's inactive