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

__dirname points to wrong package causing 'package' event to be omitted #73

Closed
lukas-zech-software opened this issue Mar 13, 2015 · 1 comment

Comments

@lukas-zech-software
Copy link

I'm using browserify 9.0.3 using module-deps 3.7.2 and my code listens on the bundle.on('package') event.
I noticed that the event is sometimes not triggered for some packages, although the package gets included properly.
It does not occur reliable even if the same code is executed twice, so it seems to be some sort of async race condition.

Example:

require('package1');
require('package2');
require('package3');

These events are fired:

bundle.on('package',function(){ //package1 });
bundle.on('package',function(){ //package3 });

I tracked the problem down to this line where the _self.emittedPkg object already contains 'package2', although the 'package' even was not yet emitted for this package.

Digging further I found that in the resolver function the following situation may occur:

// pkgdir holds the directory to 'package1'
// pkg.name holds the name of 'package2'
if (pkg && pkgdir) pkg.__dirname = pkgdir;

So it seems that the packageFilter function is called by another callback before the resolver function executes for this package? Just guessing though, I was not able to track it down further.

It seems to be similar to #67 and maybe also connected to (browserify/resolve#69)
But it differs to both issues in the fact, that __dirname does not simply point to a wrong path in the package but to a complete wrong package.

@pmowrer
Copy link
Contributor

pmowrer commented Apr 20, 2015

+1 Just debugged a similar scenario and came to the same conclusion (using versions 9.0.8 and 3.7.6 respectively).

pmowrer added a commit to pmowrer/module-deps that referenced this issue Apr 20, 2015
pmowrer added a commit to pmowrer/module-deps that referenced this issue Apr 20, 2015
pmowrer added a commit to pmowrer/module-deps that referenced this issue Apr 20, 2015
pmowrer added a commit to pmowrer/module-deps that referenced this issue Apr 20, 2015
pmowrer added a commit to pmowrer/module-deps that referenced this issue May 5, 2015
pmowrer added a commit to pmowrer/module-deps that referenced this issue May 5, 2015
@zertosh zertosh closed this as completed in 3ebfa38 May 5, 2015
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

2 participants