hughsk/envify

Error using transform

yoshuawuyts opened this issue · 3 comments

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

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 :)

Hah, that was exactly the problem. Thanks dude!

@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