micromatch / glob-fs

file globbing for node.js. speedy and powerful alternative to node-glob. This library is experimental and does not work on windows!
http://jonschlinkert.github.io/glob-fs
MIT License
55 stars 17 forks source link

TypeError: Cannot read property 'split' of undefined #10

Closed rchoudhary closed 7 years ago

rchoudhary commented 8 years ago

When trying to run the sync example from the website, I get the following error:

    return fp.split('\\').join('/');
             ^

TypeError: Cannot read property 'split' of undefined

For reference, here is the code:

var glob = require('glob-fs')({ gitignore: true });

var files = glob.readdirSync('**/*.js');
console.log(files);

My hunch is it involves line 74 of glob-fs/lib/pattern.js: this.base = path.join(this.cwd, this.parent);. Running the debugger, the path.join returns a nonsense path (the c:/ drive is in both this.cwd and this.parent and path.join just smashes them together).

Even if I fix the issue of this.pattern.re vs this.pattern.regex, I still get the same 'fp is undefined' error.

TimMurphy commented 8 years ago

Same here.

code-mattclaffey commented 8 years ago

I get this error to

paulcrussell commented 7 years ago

Happening for me as well.

Globbing with **\*
C:\Users\paulr\node_modules\micromatch\lib\utils.js:66
    return fp.split('\\').join('/');
              ^

TypeError: fp.split is not a function
    at Object.unixify (C:\Users\paulr\node_modules\micromatch\lib\utils.js:66:15)
    at Function.any (C:\Users\paulr\node_modules\micromatch\index.js:231:14)
    at isMatch (C:\Users\paulr\node_modules\glob-fs-gitignore\index.js:16:17)
    at Object.gitignore (C:\Users\paulr\node_modules\glob-fs-gitignore\index.js:32:9)
    at Handler.handle (C:\Users\paulr\node_modules\glob-fs\lib\handler.js:26:17)
    at Object.Emitter.handle (C:\Users\paulr\node_modules\glob-fs\index.js:249:18)
    at C:\Users\paulr\node_modules\glob-fs\lib\iterators.js:168:20
    at C:\Users\paulr\node_modules\glob-fs\lib\symlinks.js:28:18
    at FSReqWrap.oncomplete (fs.js:123:15)
setriosdomain commented 7 years ago

Yes It works ok on linux and mac, but not on windows. Im getting this exact error when performing any search.

setriosdomain commented 7 years ago

on the setPattern function at index.js of the lib

change from // if middleware are registered, use the glob, otherwise regex var glob = this.fns.length ? this.pattern.glob : this.pattern.re;

to

// if middleware are registered, use the glob, otherwise regex
var glob = this.fns.length
  ? this.pattern.glob
  : this.pattern.regex;

this seems to fix the prob

jonschlinkert commented 7 years ago

sorry all, I think I mentioned this elsewhere but this might be fixed by updating micromatch to the latest version. I can do this when I have a chance, or if someone wants to do a pr I'd be happy to merge

dynajoe commented 7 years ago

Updating micromatch resulted same issue.

Dan9boi commented 7 years ago

+1 for this issue :(

octachrome commented 7 years ago

I am getting the same error. This looks like a great library, more flexible than https://github.com/isaacs/node-glob, but it just doesn't work on Windows for a lot of people. Any chance of getting this fixed?

jonschlinkert commented 7 years ago

@octachrome, please see the very top of the front page of the project where it states ... This library is experimental and does not work on windows!

Any chance of getting this fixed?

We're going to do a complete refactor of this lib as soon as we have a chance. I'm not sure when that will be, but I'll make sure to publish the refactor on the dev branch and post an update here as soon as it's started

itslenny commented 7 years ago

It's exactly what @setriosdomain suggested above. It's just a typo pattern.re is undefined it is supposed to be pattern.regex

jonschlinkert commented 7 years ago

@itslenny if you want to do a pr, I'll merge it in right away. That would make it a lot easier for me to get to this. Otherwise it might be a while

itslenny commented 7 years ago

I just tried it, but the issue seems to cascade a bit, and I'm honestly not sure where the rabbit hole ends.

When it gets the pattern correctly it winds up passing an array into gitignore instead of a string that gets passed to minimatch which calls .split on an array and crashes.

I updated the minimatch version which fixes that, but then I get an expected string error from normalize-path which is a sub-dependency of minimatch.

jonschlinkert commented 7 years ago

I just tried it, but the issue seems to cascade a bit, and I'm honestly not sure where the rabbit hole ends.

Oh ok, you said "It's exactly what @setriosdomain suggested above. It's just a typo pattern.re is undefined it is supposed to be pattern.regex", so I thought you knew something I didn't. Thanks for clarifying.

danielfaust commented 7 years ago

How about adding a note on npmjs.com that this does not work on windows...

startupsandcode commented 7 years ago

I submitted a PR for this: https://github.com/micromatch/glob-fs/compare/master...lotekmedia:master It definitely works on Windows now. Thanks!

jonschlinkert commented 7 years ago

resolved by https://github.com/micromatch/glob-fs/pull/20