es128 / progeny

:baby: Recursively finds dependencies of style and template source files
MIT License
29 stars 15 forks source link

TypeError: Cannot read property 'match' of null #34

Open orelmi opened 7 years ago

orelmi commented 7 years ago

I get this error when building with gulp.

    .map(function (val) {
     ^

TypeError: Cannot read property 'match' of null at C:\Users\xxxx\node_modules\progeny\index.js:106:21 at Array.map (native) at parseDeps (C:\Users\xxxx\node_modules\progeny\index.js:104:10) at C:\Users\xxxx\node_modules\progeny\index.js:270:9 at tryToString (fs.js:455:3) at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)

I changed the code like that ( if (val != null) added) and it works fine. Please, tell me why val can be . If the change is correct add it to the repository.

(index.js) at line 104

.map(function (val) { var last = multipass[multipass.length - 1]; if (val != null) return val.match(last)[1]; });

Thanks

es128 commented 7 years ago

Can you show me the source file and settings that caused the error to begin with? Was it a sass file using the built-in settings?

ln-e commented 7 years ago

I suppose i have the same problem. My scss file starts with

@import '../../global/home';
@import url('http://fonts.googleapis.com/css?family=Russo+One&subset=cyrillic');
#page {
  @include gradient-bg(#03254b #012652);
}

And it fails

node_modules/progeny/index.js:106
          return val.match(last)[1];
                    ^

TypeError: Cannot read property 'match' of null
    at ./node_modules/progeny/index.js:106:21
    at Array.map (native)
    at parseDeps (./node_modules/progeny/index.js:104:10)
    at run (./node_modules/progeny/index.js:313:7)
    at ./node_modules/progeny/index.js:329:11
    at tryToString (fs.js:456:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:443:12)
Segmentation fault: 11

But if i change like so

@import url('http://fonts.googleapis.com/css?family=Russo+One&subset=cyrillic');
@import '../../global/home';
#page {
  @include gradient-bg(#03254b #012652);
}

or so

@import '../../global/home';
@import url('http://fonts.googleapis.com/css?family=Russo+One&subset=cyrillic');
.another {
  content: ''; // <- quotes here
}
#page {
  @include gradient-bg(#03254b #012652);
}

or so

@import '../../global/home';
@import url('http://fonts.googleapis.com/css?family=Russo+One&subset=cyrillic');
#page {
  // @include gradient-bg(#03254b #012652);
}

it works.

wmnnd commented 7 years ago

I have encountered the same problem using sass-brunch.

My scss file starts like this:

@import "compass/reset";
@import "compass/typography/vertical_rhythm";
@import url("https://fonts.googleapis.com/[…]");

This made progeny throw the following error:

error: Compiling of scss/styles.scss failed. TypeError: Cannot read property 'match' of null
  at ./node_modules/progeny/index.js:106:21
  at Array.map (native)
  at parseDeps (./node_modules/progeny/index.js:104:10)
  at run (./node_modules/progeny/index.js:313:7)
  at SassCompiler.progeny (./node_modules/progeny/index.js:320:7)
  at ./node_modules/micro-promisify/index.js:8:14
  at SassCompiler.<anonymous> (./node_modules/micro-promisify/index.js:6:10)
  at SassCompiler.compile (./node_modules/sass-brunch/index.js:208:17)

However, when I change the beginning of the file to

@import url("https://fonts.googleapis.com/[…]");
@import "compass/reset";
@import "compass/typography/vertical_rhythm";

or

@import "compass/reset";
@import url("https://fonts.googleapis.com/[…]");
@import "compass/typography/vertical_rhythm";

everything works without problems.

VladimirKasatkin commented 6 years ago

It looks like this error appears when we have only one import from url in file:

//---------------------------------------------------------
// Global UI Styling
//---------------------------------------------------------
@import 'https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700';

If I add extra import from empty file (I called it "_nothing.scss" and put in the same folder) then the error goes away.

//---------------------------------------------------------
// Global UI Styling
//---------------------------------------------------------
@import 'https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700';
@import 'nothing';
thecristen commented 6 years ago

I've got this too with using sass-brunch, but it happens when I import the gutenberg library. Turms out its config has a conditional import url statement. Thanks @wmnnd and @VladimirKasatkin for helping me figure out that one...

yama-dev commented 5 years ago

Why do not you try to fix it as follows?

progeny()

progeny({
  multipass: [
    /@import[^;:]+;/g,
    /\s*['"][^'"]+['"]\s*,?/g,
    /(?:['"])([^'"]+)/
  ]
})

Exclude import path including ":"