BlessCSS / bless

CSS Post-Processor
blesscss.com
MIT License
282 stars 60 forks source link

.TypeError: Cannot read property 'reduce' of undefined #93

Closed Dragod closed 8 years ago

Dragod commented 8 years ago

While running blessc count mycss.css or blessc chunk mycss.css i got this error:

.TypeError: Cannot read property 'reduce' of undefined

Node 4.1.1 Npm 3.3.0 Blessc 4.0.0 Win 8.1

AaronAsAChimp commented 8 years ago

Thanks for the issue. Can you please provide a minimal example that reproduces this issue? A similar issue was posted in grunt-bless regarding the @charset rule.

fk commented 8 years ago

+1 – running into the same issue in a project I just took over.

Using Node v5.5.0, NPM v2.7.4 and BlessCSS/blessc v4.0.0, a stylesheet containing only @charset "UTF-8"; yields the described error message when I do a blessc count test.css.

BrandonNoad commented 8 years ago

As mentioned in BlessCSS/gulp-bless#15, I ran into this too.

The following css rule when run through bless seems to cause the error:

@page {
  margin: 0.34in; 
}

https://www.w3.org/TR/css3-page/#page-box-page-rule

philipjfulcher commented 8 years ago

I've also run into this issue recently using grunt-bless. We compile our SCSS along with the Foundation framework. This CSS line is where Bless fails:

@page{
 margin:.34in
}

Commenting out that SCSS where that's generated allows things to progress.

My stack trace from when it fails:

Warning: Cannot read property 'reduce' of undefined Use --force to continue.
TypeError: Cannot read property 'reduce' of undefined
    at countRules (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\lib\count.js:26:17)
    at count (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\lib\count.js:45:14)
    at j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\lib\count.js:27:20
    at Array.reduce (native)
    at countRules (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\lib\count.js:26:18)
    at count (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\lib\count.js:45:14)
    at chunks$ (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\lib\chunk.js:52:46)
    at tryCatch (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\node_modules\babel-runtime\regenerator\runtime.js:72:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\node_modules\babel-runtime\regenerator\runtime.js:334:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (j:\Arsenal\rsi-main-website-2015\themes\rsi-2015\node_modules\bless\node_modules\babel-runtime\regenerator\runtime.js:105:21)

Node 5.5.0 Npm 3.3.12 Bless 4.0.0

johnsardine commented 8 years ago

Hi, im also having the same issue, but when using with grunt. For some reason i cant install this standalone. Does anyone have a solution to the reduce issue? Thank you

dailyraisin commented 8 years ago

+1 I see this too using the cli version.

luke3butler commented 8 years ago

I tried multiple versions of node without success. I installed 3.0.3 to fix this issue in the meantime.

npm install -g bless@3.0.3

I was also getting the following error with version 4:

Failed: TypeError: Cannot read property 'parseArgs' of undefined
TypeError: Cannot read property 'parseArgs' of undefined
    at parseCliArgs (/Users/username/.nvm/versions/node/v5.6.0/lib/node_modules/bless/lib/parse-cli-args.js:64:47)
devotox commented 8 years ago

Is there any fix or work around as of yet?

paulyoung commented 8 years ago

Sorry for the trouble everyone. Unfortunately I won't be able to look into this until after next week. @BlessCSS/owners are any of you able to help?

I'm also experiencing the issue described in #95, which means I'd need to fix that before addressing anything else.

mtscout6 commented 8 years ago

I'm hoping that #96 will help with this, but I can't guarantee it. A number of the dependencies were out of date causing issues. If you can try it against the changes there and let us know if that helps that would be great. Otherwise we need to get a PR up with a failing test case for this scenario.

anthony-butcher commented 8 years ago

I'm just using 0.2.0 for now to get around this.

paulyoung commented 8 years ago

@BlessCSS/contributors I've added fixtures to a branch called page which demonstrate this error.

joaquin-corchero commented 8 years ago

Good morning,

I have been checking the package and it seems like there is an issue on the countRules(rules) function. When it tries to read the rules for @page, the rules are null and it breaks.

By modifying the countRules(rules) on the count.js (on the transformed version) method to the following:

  function countRules(rules) {
     if(!rules){
         return 0;
     }
    return rules.reduce(function (acc, rule) {
      return acc + count(rule);
    }, 0);
  }

It works but not sure if that would break anything else...

I beleieve that ideally no @page should exist anywhere as less doesn't like @ too much unless they are used on variables...

damienleroux commented 8 years ago

Is there any reason why "rules" must be existing? I made the modification from @joaquin-corchero and it resolve my problem. But not knowing well Bless process, I wonder...

mtscout6 commented 8 years ago

The bigger question is whether the @page rule counts against the selector limit for IE <= IE8. The real fix would actually be in the switch we use to determine how to count the selectors based on the AST.

damienleroux commented 8 years ago

Ok I see, do you plan to complete the switch or do you prefer I fork the repo?

mtscout6 commented 8 years ago

We'd be open to a pull request for a fix.

Dariia commented 8 years ago

@joaquin-corchero tried to use your method in count.js, the error disappeared. Chunk creates files. But they are empty.

joaquin-corchero commented 8 years ago

@Dariia what we ended up doing was removing any instances of '@page' from the source files, that fixed the issue.

yvanavermaet commented 8 years ago

Also encounter this problem with @charset. Removing that fixes the issue. Any ETA on a fix?

morph3ux commented 8 years ago

I am having the same issue. I have to mention that when I run gulp inside an old installation directory it works. I've copied over the entire node_modules to the new installation directory and it works, but this is a manual undesired fix. Later today I'll compare the two directories and see the diff

makque commented 8 years ago

For bless admins, any verdict on my Pull Request? I've been holding off a feature for our site because of this, I just want to know if any action will be implemented for this fix immediately otherwise I'll push a dirty temp fix for our site to get around this.

Thanks!

@morph3ux - it's probably a version 3 copy of bless, I only encountered this issue when gulp-bless, which the plugin I'm using laravel-elixir-bless, updated to version 4 of bless, unfortunately there's no way for me to rollback to a previous version

morph3ux commented 8 years ago

@makque Thanks for your reply! Yeah, you might be right about the version. Let's hope we'll get a fix soon so we don't have to hack our apps to solve the issue. And backup. Always!

makque commented 8 years ago

@makque no worries, I already submitted a PR for the fix, #99, I think he's concerned with the @page, just waiting for a reply, for my case I just need a fix for @charset 'cause SASS prepends an @charset on compile

mtscout6 commented 8 years ago

This should be fixed in v4.0.1