hughsk / disc

:chart_with_upwards_trend: Visualise the module tree of browserify project bundles and track down bloat.
http://hughsk.io/disc
Other
1.33k stars 83 forks source link

Cannot read property 'source' of undefined #24

Closed Sinewyk closed 8 years ago

Sinewyk commented 9 years ago

When i try verbatim what you said in your example since v1.0.0

browserify --full-paths index.js > bundle.js
discify bundle.js > disc.html
open disc.html

I get this

E:\Prog\front-web\node_modules\disc\index.js:100
        size: row.source.length
                 ^
TypeError: Cannot read property 'source' of undefined
    at tree.name (E:\Prog\front-web\node_modules\disc\index.js:100:18)
    at flat.unflatten.delimiter (E:\Prog\front-web\node_modules\disc\node_modules\file-tree\index.js:15:5)
    at next (E:\Prog\front-web\node_modules\disc\node_modules\file-tree\node_modules\async-reduce\index.js:11:7)
    at reduce (E:\Prog\front-web\node_modules\disc\node_modules\file-tree\node_modules\async-reduce\index.js:23:3)
    at tree (E:\Prog\front-web\node_modules\disc\node_modules\file-tree\index.js:13:3)
    at json (E:\Prog\front-web\node_modules\disc\index.js:94:3)
    at Function.bundle (E:\Prog\front-web\node_modules\disc\index.js:130:10)
    at handle (E:\Prog\front-web\node_modules\disc\bin\discify:56:8)
    at disc.bundle.mode (E:\Prog\front-web\node_modules\disc\bin\discify:51:5)
    at handler (E:\Prog\front-web\node_modules\disc\node_modules\map-async\index.js:36:29)

var row = byid[id] is the culprit

id was correctly the entry file at first, but it seems that he still didn't found the data inside byid, i'll try some Object.keys on byid to check what happened after I eat something.

any ideas on your side ?

Sinewyk commented 9 years ago

Oh yeah. That's it, some kind of path issue. My first file is in the object as a relative path

process.cwd() === '/home/sinewyk/dev/repo' './app/scripts/main.js'

while it's trying to get '/home/sinewyk/dev/repo/app/scripts/main.js'

all others entries in the object have the correct expected form by disc, that is stuff like

'/home/sinewyk/dev/repo/node_modules/underscore/underscore.js'

Any ideas where it could be coming from ?

Sinewyk commented 9 years ago

Ok ... fixed, I just needed to send an absolute path into browserify instead of a relative one, so that the entry file also had an expected absolute path instead of a relative one.

Maybe edit the readme, fullPaths: true needed, AND send and absolute path down the browserify bundle API.

hughsk commented 9 years ago

@Sinewyk this is a bug in browserify – maybe you should open an issue or PR to have the supplied path made absolute when using fullPaths?

cowwoc commented 9 years ago

@Sinewyk I am running into the same problem. Did you open a bug report with Browserify? If so, where?

Sinewyk commented 9 years ago

Oh my bad. I bypassed the problem. I had a "classic" browserify workflow with all my custom things that worked. And then I simply run disc on the result file with --open.

Exactly like that (for example with gulp, but you can do that with anything really).

gulp.task('deps-tree', ['browserify'], function() {
    var discSpawn = spawn('./node_modules/.bin/discify', ['./app/assets/scripts/bundle.js', '--open']);

    discSpawn.on('close', function() {
        process.exit(0);
    });
});

don't forget to send fullPaths: true as option inside the browserify command.