Expose property doesn't work when requiring a module name
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.
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.
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.
+1 Only fails when using a module name.
+1
+1 browserify 6.x breaking using the CLI -r option with export alias
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]"
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)
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...
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.
Roger. Currently depending ^5.8.0 as workaround.
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.
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 ...
@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
And it doesn't look like the usage of --full-paths makes a difference on my end.
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, try aliasing in package.json. Works for me with browserify 6.2.0
"browser": {
"fs": "browserify-fs"
}
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.
I was having the same issue and #991 fixed it for me as well.
Same issue too, #991 fixed it too
I ran into the same blocking issue too. #991 fixes it too!