seangenabe / browserify-breakdown

break down and analyze browserify/browser-pack bundles
3 stars 0 forks source link

Fix CLI breaking on nodes wihtout deps #3

Closed stefanmaric closed 7 years ago

stefanmaric commented 7 years ago
browserify-breakdown < _dist/js/index.min.js
/home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:40
    var nodes = node.deps.map(function(node) {
                         ^

TypeError: Cannot read property 'map' of undefined
    at prepareForArchyInput (/home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:40:26)
    at /home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:41:14
    at Array.map (native)
    at prepareForArchyInput (/home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:40:27)
    at /home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:41:14
    at Array.map (native)
    at prepareForArchyInput (/home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:40:27)
    at /home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:41:14
    at Array.map (native)
    at prepareForArchyInput (/home/sam/n/lib/node_modules/browserify-breakdown/bin/cmd.js:40:27)
coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling b58ae21ccbd219b8b48b98b00d5683c2f585404e on stefanmaric:master into c8e6e2bcd77bd3e5dbb3259dfaf7ebc568f54a4c on seangenabe:master.

seangenabe commented 7 years ago

I've merged your PR, but I'm also interested to know what specific module causes this so I can investigate and write some tests for it.

stefanmaric commented 7 years ago

@seangenabe I spent some good time debugging the app and finally found out what produces this error: it is the inserGlobals option of browserify.

You can replicate:

mkdir test
cd test
npm install browserify browserify-breakdown@1.0.2
echo 'console.log("test")' > entry.js
# this one succeeds
./node_modules/.bin/browserify entry.js | ./node_modules/.bin/browserify-breakdown
# this one fails
./node_modules/.bin/browserify entry.js --insert-globals | ./node_modules/.bin/browserify-breakdown

I tested with node@6.11.0 and npm@3.10.10 this time, but I've seen this happen with a wide range of versions.