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

b.add() API change since 10.1.1 ? #1332

Closed
benpptung opened this issue Jul 19, 2015 · 2 comments
Closed

b.add() API change since 10.1.1 ? #1332

benpptung opened this issue Jul 19, 2015 · 2 comments

Comments

@benpptung
Copy link

Since 10.1.1, b.add() will not resolve to a node module.

For example:

Before 10.1.1:

I can b.add('superagent') to bundle a node module in a project.

After 10.1.1:

I will get "Cannot find module"

To reproduce it.

npm init test // init a project
npm install superagent --save // simply add a node module
npm install browserify // install browserify

Set up a ./test.js in the project:

var browserify = require('browserify');
var b = browserify();
b.add('superagent');
b.bundle(function(err, buf) {
    if (err) return console.log(err):
    console.log(buf.toStrinig())
});

In command line, node ./test.js will callback error 'Cannot find module'.
But, if we change to browserify@10.1.0

npm install browserify@10.1.0

We'll get a bundled code.

@jmm
Copy link
Collaborator

jmm commented Jul 22, 2015

@benpptung The behavior did change, yes. See #1248 and #1268. Did the API change? Not really? In my opinion b.add() is too vaguely specified, so who can say how it's intended to work? Although maybe something is implied by contrasting it with b.require()'s documentation:

The file param is anything that can be resolved by require.resolve().

For the moment you should be able to work around the issue by doing:

b.add(require.resolve('superagent'))

I don't want to be the one to close and bury this issue because I don't think the situation has been properly dealt with yet (see my comments in the other issues).

@benpptung
Copy link
Author

@jmm Thank you for update.
I was asking because I wrote a package http://github.com/benpptung/appstackr, which depends on browserify a lot, so this was a little shock to me when I saw it didn't work.

Sorry for my words, I agree it is a behavior change, not API change. Yes, I was misguided by the b.require()'s documentation. I'll close this issue, because I think this is just not properly addressed in the b.add() documentation. Thank you for your clarification. :)

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

No branches or pull requests

2 participants