-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Can't defined exposed name with require option #881
Comments
I'm experiencing a similar problem: b.require('our-framework/lib/client-polyfills/continuation-local-storage', {
expose: 'continuation-local-storage'
}); and b.require('lodash', {
expose: 'underscore'
}); fail to work correctly on 5.11.0. I've spent some hours looking into the issue but I can't quite understand what is actually going on in browserify. I noticed that the compiled javascript now contains Really not sure how to fix this problem. |
+1 |
A temporary workaround is to use a path instead of a module reference. E.g. this doesn't work b.require('react/addons', {expose: 'react'}); This however does b.require('./node_modules/react/addons', {expose: 'react'}); |
This is still an issue in 6.3.3. Say I'm doing: b.require('superagent', {expose: 'thingy'}) The problem seems to be here - the var row = typeof file === 'object'
? xtend(file, opts)
: (isExternalModule(file)
? xtend(opts, { id: expose || file })
: xtend(opts, { file: file })
)
;
if (!row.id) {
row.id = expose || file;
} So I get:
If I change that section to set the var row = typeof file === 'object'
? xtend(file, opts)
: xtend(opts, { file: file })
;
if (!row.id) {
row.id = expose || file;
} ...then it works as expected. I don't grok the codebase, so I don't know what the significance of the |
+1 |
@litek fix works as well, and doesn't require you to dig into the browserify codebase at all. It has me thinking that this might have something to do with resolving paths but I can't be too sure. EDIT: this was a lie. It actually did not work properly for me. I set lodash's target to underscore, and that allowed backbone to use lodash but the rest of my app did not see lodash as a dependency |
Okay I did some more digging and i found a pretty interesting difference when using the but when I do it i do it like this so the real question is, is anything inside |
Using the programmatic API, I try to bundle a file and expose it with a simple name:
The resulting file keeps the path as the module identifier.
I digged in the source code and the problematic part seems to be:
https://github.com/substack/node-browserify/blob/master/index.js#L119-L126
I'm on windows and my path is C:\Folder\file.ext and the regex test evaluates to false (path don't start by . or /) so the id is set to the path.
Then the exposed name is not assigned since the id is already defined.
I don't really get what is the purpose of lines 119-121 but I guess it needs to be changed to support windows. If someone can explain it to me I can try to submit a pull request with windows support.
Edit:
It could also be a bug (I don't see why the expose parameter shouldn't be used in any case),
in that case changing the line 121 with
: xtend(opts, { id: (expose || file), file: file })
should fix the problem.The text was updated successfully, but these errors were encountered: