Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including envify as a transform causes browserify to throw an error #32

Closed
toddself opened this issue Sep 1, 2015 · 6 comments
Closed

Comments

@toddself
Copy link

toddself commented Sep 1, 2015

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:

Unable to build /home/user/scripto2/src/static/js/entrypoint.js path must be a string Error: path must be a string
        at /home/user/scripto2/node_modules/browserify/node_modules/resolve/lib/async.js:16:16
        at doNTCallback0 (node.js:407:9)
        at process._tickDomainCallback (node.js:377:13) { err:
       { [Error: path must be a string]
         stream:
          Labeled {
            _readableState: [Object],
            readable: true,
            domain: null,
            _events: [Object],
            _eventsCount: 4,
            _maxListeners: undefined,
            _writableState: [Object],
            writable: true,
            allowHalfOpen: true,
            _options: [Object],
            _wrapOptions: [Object],
            _streams: [Object],
            length: 1,
            label: 'deps' } } }

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 the transform keys in package.json -- they both fail). However, if you do node_modules/.bin/browserify -t envify entrypoint.js it'll work...

@yoshuawuyts
Copy link
Collaborator

This is todd.

FTFY 😁

But to answer your question: could you try doing require('envify/custom'), I suspect that will resolve your issue.

@toddself
Copy link
Author

toddself commented Sep 1, 2015

😆

Ah @yoshuawuyts you are my hero this morning!

Thanks again!

@toddself toddself closed this as completed Sep 1, 2015
@toddself
Copy link
Author

toddself commented Sep 1, 2015

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?

@yoshuawuyts
Copy link
Collaborator

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 usage

Not entirely sure why this is how it is, pretty sure we could do a better job (':

@damncabbage
Copy link

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

@zekedroid
Copy link

@damncabbage: saved me after hours of debugging. This should go into the README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants