Closed toddself closed 9 years ago
This is todd.
FTFY :grin:
But to answer your question: could you try doing require('envify/custom')
, I suspect that will resolve your issue.
:laughing:
Ah @yoshuawuyts you are my hero this morning!
Thanks again!
But after looking at the code I'm confused as to why this works?
It looks like including the base project actually calls custom with process.env
, where as calling custom directly with no args short-circuits into process.env
.
Any idea on why this actually works?
I believe the files are used as follows:
./custom.js
is called for JS usage./index.js
is called for package.json
transforms (not completely sure about this though)bin/envify
is called for CLI usageNot entirely sure why this is how it is, pretty sure we could do a better job (':
For someone who stumbled across this ticket with the same confusing problem:
From the example:
browserify('entrypoint.js').transform(require('envify')()).bundle()
Should actually be:
browserify('entrypoint.js').transform(require('envify')).bundle()
// No () here; it's already ready for use ---^
(The default version of envify
is already "applied". I think this was a little unclear from the docs; the notation in the "Module Usage" headings was unfamiliar to me.)
@damncabbage: saved me after hours of debugging. This should go into the README.md.
This is odd.
If I do:
browserify -t envify entrypoint.js
it will work.
However, if I do:
browserify('entrypoint.js').transform(require('envify')()).bundle()
browserify will crash with:
If I remove the
.transform
call everything works correctly.browserify 10.2.6 (as well as 11.0.1) envify 3.4.0
I've created a simple test case here: https://github.com/toddself/envify-example
if you do
node bundle.js
you'll see the error. if you remove the call to.transform
it'll work. (it doesn't matter if you put envify in the.transform
call or in thetransform
keys inpackage.json
-- they both fail). However, if you donode_modules/.bin/browserify -t envify entrypoint.js
it'll work...