hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
902 stars 57 forks source link

Error using transform #7

Closed yoshuawuyts closed 10 years ago

yoshuawuyts commented 10 years ago

I'm probably doing something wrong, whenever I call envify my cli throws. Could you help me out?

task.js:

/**
 * Compile JS
 */

gulp.task('modules', function() {
  browserify(__dirname + '/client/modules/index/index.js')
    .transform(envify({NODE_ENV: process.env.NODE_ENV}))
    .transform({global: true}, 'uglifyify')
    .bundle({debug: true})
    .pipe(source('build.js'))
    .pipe(gulp.dest(__dirname + '/build/'));
});

cli error:

❯ versity build
/home/yoshua/Code/versity
[17:40:14] Starting 'styles'...
[17:40:14] Finished 'styles' after 16 ms
[17:40:14] Starting 'modules'...
[17:40:14] Finished 'modules' after 9.79 ms
[17:40:14] Starting 'assets'...
[17:40:14] Finished 'assets' after 785 μs
[17:40:14] Starting 'default'...
[17:40:14] Finished 'default' after 52 μs
/home/yoshua/Code/versity/node_modules/browserify/index.js:372
        return function (file) { return t.call(this, file, opts) };
                                          ^
TypeError: Object #<Stream> has no method 'call'
    at /home/yoshua/Code/versity/node_modules/browserify/index.js:372:43
    at makeTransform (/home/yoshua/Code/versity/node_modules/browserify/node_modules/module-deps/index.js:209:21)
    at /home/yoshua/Code/versity/node_modules/browserify/node_modules/module-deps/index.js:186:9
    at Deps.getTransforms (/home/yoshua/Code/versity/node_modules/browserify/node_modules/module-deps/index.js:191:7)
    at Deps.readFile (/home/yoshua/Code/versity/node_modules/browserify/node_modules/module-deps/index.js:164:25)
    at /home/yoshua/Code/versity/node_modules/browserify/node_modules/module-deps/index.js:280:14
    at onresolve (/home/yoshua/Code/versity/node_modules/browserify/node_modules/module-deps/index.js:150:14)
    at /home/yoshua/Code/versity/node_modules/browserify/index.js:737:13
    at next (/home/yoshua/Code/versity/node_modules/browserify/index.js:781:17)
    at /home/yoshua/Code/versity/node_modules/browserify/index.js:785:33
hughsk commented 10 years ago

Hey! How're you requiring envify? You should use the following if you want to pass in your own environment object:

var envify = require('envify/custom')

The main envify transform is for using with the command-line interface so won't take any arguments directly :)

yoshuawuyts commented 10 years ago

Hah, that was exactly the problem. Thanks dude!

slorber commented 9 years ago

@hughsk I think you should add in the doc an exemple of using envify (not custom) because I just did the same mistake :) I found it quite confusing and understood that if we are not using the command line we should use envify custom