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

TypeError: Cannot read property 'source' of undefined #30

Open
cowwoc opened this issue Jan 26, 2015 · 18 comments
Open

TypeError: Cannot read property 'source' of undefined #30

cowwoc opened this issue Jan 26, 2015 · 18 comments

Comments

@cowwoc
Copy link

cowwoc commented Jan 26, 2015

This issue is a variation of #24 (same error but I use absolute paths).

  1. Run the gulp code found at TypeError: Invalid non-string/buffer chunk #29 (comment) but replace the paths (passed into add() and dest()) with absolute paths.
  2. Exception is thrown:
C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\index.js:99
        size: row.source.length
                 ^
TypeError: Cannot read property 'source' of undefined
    at tree.name (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\index.js:99:18)
    at flat.unflatten.delimiter (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\node_modules\file-tree\index.js:15:5)
    at next (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\node_modules\file-tree\node_modules\async-reduce\index.js:11:7)
    at reduce (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\node_modules\file-tree\node_modules\async-reduce\index.js:23:3)
    at tree (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\node_modules\file-tree\index.js:13:3)
    at json (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\index.js:95:3)
    at bundle (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\index.js:129:10)
    at BufferList._callback (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\index.js:27:5)
    at BufferList.end (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\node_modules\bl\bl.js:75:10)
    at Stream.method [as end] (C:\Users\Gili\Documents\realestate\frontend\node_modules\disc\node_modules\duplexer\index.js:47:39)

This issue is reproducible 100% of the time.

@hughsk
Copy link
Owner

hughsk commented Jan 26, 2015

@cowwoc could you please include the bundled output from browserify that's breaking here? I need to be able to reproduce it on my machine to be able to help with this one.

@cowwoc
Copy link
Author

cowwoc commented Jan 26, 2015

@hughsk Please email me at [scrubbed] and I'll send you the bundle privately.

@GalCohen
Copy link

GalCohen commented Feb 8, 2015

got the same issue here too

@chpio
Copy link

chpio commented Mar 2, 2015

here too :(

@formula1
Copy link

If you are on windows, you will likely need to do a path.normalize(__dirname+"/path/to/file) when creating your bundle.

It seems as though browserify doesn't do it for you : /

A working Example (for me):

function(req,res){
  browserify({
    fullPaths: true
  })
  .add(path.normalize(__dirname+"/browser.js"))
  .ignore("prompt")
  .transform({
    global: true
  }, 'uglifyify')
  .bundle().pipe(disc()).pipe(res);
}

Full code here. Go to localhost:3000/fresh or localhost:3000/disk

An alternative is require.normalize which allows you to give a valid require-able and it will return a valid string that matches your operating systems pathing structure (ie windows or everone else)

Btw, if theres ever an issue with file loading and you're on windows:

  • Make sure you use path.normalize any paths you will require
  • consider installing ubuntu or a linux distro
  • Read this again to not get filled with hatred and hopelessness

mathisonian added a commit to mathisonian/disc that referenced this issue Apr 7, 2015
Thanks for the library - it's been very useful!

I hit the same problem as hughsk#24, hughsk#30. Using a full path for the browserify input fixed it for me, as well as for other people in those issue threads.
@nemo
Copy link

nemo commented Apr 20, 2015

This still happens to me even after using fullPaths: true, but only when I generate the bundle through gulp. Using command line works just fine.

Here's the gulp task:

var gulp = require('gulp');
var config   = require('../config');
var browserify = require('browserify');
var open = require('opener');
var disc = require('disc');
var fs = require('fs');


gulp.task('build:disc', function() {
    var output = config.destDirectory + '/disc.html';

    var bundler = browserify(config.sourceDirectory + '/' + config.sourceEntry, {
      fullPaths: true
    });

    bundler.bundle()
      .pipe(disc())
      .pipe(fs.createWriteStream(output))
      .once('close', function() {
        open(output);
      });

});

@formula1
Copy link

@nemo are you on windows?

@nemo
Copy link

nemo commented Apr 21, 2015

@formula1 Nope - OSX.

@formula1
Copy link

What is the value of config.souceDirectory + "/" config.sourceEntry? I've been able to get this running on multiple systems so I was hoping it was a windows only issue

@nemo
Copy link

nemo commented Apr 22, 2015

Here's how config is defined:

var config = {};

config.destDirectory = "./dist";
config.sourceDirectory = "./app";
config.sourceEntry = 'index.js';

And in case it's helpful, here's the versions for what I'm using:

{
    "browserify": "^9.0.7",
    "disc": "^1.3.2",
    "gulp": "^3.8.11",
    "opener": "^1.4.1"
}

@formula1
Copy link

./Anything is a relative path similar to ../something/above. So when you specify the {fullPaths:true} What your implicitly saying is here is a direct path from point A to point B without taking advantage of the cwd. so instead of ./dist you'll want __dirname+"/dist" This will result in something like /home/name/something/else/path/to/your/file/dist.

I'm sorry if that is confusing, not sure the best way to explain.

@cheton
Copy link

cheton commented Apr 22, 2015

In index.js#L91, you can resolve mod.id to an absolute path if it is a relative path.
For example:

  var byid = modules.reduce(function(memo, mod) {
    var id = (function(id) {
      if (path.resolve(id) !== path.normalize(id)) { // check for relative path
        return path.resolve(process.cwd(), id); // resolves "id" to an absolute path
      }
      return id;
    }(mod.id));
    memo[id] = mod;
    return memo
  }, {})

I'm not sure if above code example may cause any side effects, but it did fix my issue even if using a relative path.

@nemo
Copy link

nemo commented Apr 23, 2015

Ah I see. Yeah, using __dirname and path.normalize fixed the problem for me :)

@formula1
Copy link

You probably don't need normslize btw, that's usually a windows issue. Mac and Linux can generally path as freely as they like so long as the code base isn't going to be shared to windows

@nemo
Copy link

nemo commented Apr 24, 2015

Without path.normalize, the error kept showing up on OS X because I had relative paths based on the __dirname in there. (__dirname + "/../../index.js" etc.)

@formula1
Copy link

Ah, makes sense.

@JorritPosthuma
Copy link

With @cheton his patch, it also fixed it in our setup!

@glortho
Copy link

glortho commented Oct 15, 2015

@cheton patch worked for me too

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

9 participants