browserify icon indicating copy to clipboard operation
browserify copied to clipboard

Expose property doesn't work when requiring a module name

Open tleunen opened this issue 12 years ago • 29 comments

With the latest version (5.9.1), aliasing a module name doesn't work anymore. browserify -r fs:browserify-fs doesn't create the alias. With an older version (4.2.3), an alias was created with the same command.

No issue with specifying a file instead of a module name.

tleunen avatar Aug 04 '14 02:08 tleunen

I ran into this issue last week. I think it may be a dup of #839. It looks like #839 is tied to the programmatic approach and this is tied to the command line interface, though. I ran into the problem using the command line interface.

nathanbowser avatar Aug 04 '14 16:08 nathanbowser

I have this issue trying to use the command line with browserify-fs. Browserify 3.46.1 works but it seems that anything above 4.0.0 fails.

bmpvieira avatar Aug 12 '14 14:08 bmpvieira

+1 Only fails when using a module name.

iamrandys avatar Aug 30 '14 15:08 iamrandys

+1

gobwas avatar Sep 18 '14 11:09 gobwas

+1 browserify 6.x breaking using the CLI -r option with export alias

programmarchy avatar Oct 20 '14 16:10 programmarchy

Issue also exists when not using the cli. Personally spotted at 6.1.0. The expose property on a file is not honored and cannot be resolved later.

bundle.require (tmpFilePath, { expose:'configuration' });

This line on its own with no other source files bundled is sufficient to trigger "cannot find module configuration from [absolute directory path]"

shenanigans avatar Oct 22 '14 02:10 shenanigans

Adding more info, this problem only occurs when using the --full-paths option.

Here's the gist: https://gist.github.com/programmarchy/1655e571b6bb36f17c02

(I'm using browserify 6.2.0)

programmarchy avatar Oct 29 '14 19:10 programmarchy

Did a little spelunking, and found a clue in index.js:297

    var dopts = {
        index: !opts.fullPaths && !opts.exposeAll,
        dedupe: true,
        expose: this._expose
    };

From deps-sort:

opts.index - when true, for each module-deps row, insert row.index with the numeric index and row.indexDeps like row.deps but mapping require strings to row indices

The whole point of using --full-paths is to use the full path instead of a numeric index, but that does appear to be what's causing the issue of the required module not being found. Going to look deeper into how deps are looked up in other parts of browserify...

programmarchy avatar Oct 29 '14 20:10 programmarchy

Pinging @shenanigans @gobwas @iamrandys @bmpvieira @nathanbowser @tleunen

Is the error you are getting: "Uncaught Error: Cannot find module [path to your module]" ?

Just want to make sure we are all discussing the same issue.

programmarchy avatar Oct 30 '14 21:10 programmarchy

Roger. Currently depending ^5.8.0 as workaround.

shenanigans avatar Oct 30 '14 21:10 shenanigans

After more investigation, I think this is related to browser-pack step of browserify.

When I bundle without --full-paths, the packing in my gist above looks like this:

{"events":2,"nyan":undefined}

With --full-paths, it looks like this

{"events":"/usr/local/lib/node_modules/browserify/node_modules/events/events.js","nyan":"/path/to/kitten.js"}

I think that it should instead look like this:

{"events":"/usr/local/lib/node_modules/browserify/node_modules/events/events.js","nyan":undefined}

In fact, when I manually patch my bundle, it works. Still looking into why.

programmarchy avatar Oct 30 '14 21:10 programmarchy

With the example from my first post, here is what I get, with the version 6.2.0

browserify -r fs:browserify-fs
Error: Cannot find module 'browserify-fs' from ...

tleunen avatar Oct 30 '14 21:10 tleunen

@programmarchy Yea, if I run something like this:

browserify -r lodash:underscore -r ./assets/js/main.js:main

It will spit out

Error: Cannot find module 'underscore' from '/Users/koopa/dev/dash/

That's using browserify 6.2.0

nathanbowser avatar Nov 03 '14 15:11 nathanbowser

And it doesn't look like the usage of --full-paths makes a difference on my end.

nathanbowser avatar Nov 03 '14 15:11 nathanbowser

Sorry for the comment spam, but I should also mention I'm still using [email protected] because the 5.x and 6.x versions have this problem.

nathanbowser avatar Nov 03 '14 15:11 nathanbowser

@nathanbowser, try aliasing in package.json. Works for me with browserify 6.2.0

  "browser": {
    "fs": "browserify-fs"
  }

Fedia avatar Nov 07 '14 17:11 Fedia

https://github.com/substack/node-browserify/pull/991 fixes the combination of fullPaths and expose for me, if anyone else wants to see if that works for them.

mwiencek avatar Nov 13 '14 21:11 mwiencek

I was having the same issue and #991 fixed it for me as well.

athaeryn avatar Nov 13 '14 22:11 athaeryn

Same issue too, #991 fixed it too

nervo avatar Nov 17 '14 21:11 nervo

I ran into the same blocking issue too. #991 fixes it too!

olivierphi avatar Nov 23 '14 14:11 olivierphi