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 'length' of undefined #1768

Closed
dortamiguel opened this issue Aug 22, 2016 · 51 comments
Closed

TypeError: Cannot read property 'length' of undefined #1768

dortamiguel opened this issue Aug 22, 2016 · 51 comments

Comments

@dortamiguel
Copy link

Since today whenever I do a clean install of gulp I get the following error:

TypeError: Cannot read property 'length' of undefined
[10:38:42] TypeError: Cannot read property 'length' of undefined
    at flattenGlob (/Users/miguel/src/reco2/node_modules/glob2base/index.js:9:25)
    at setToBase (/Users/miguel/src/reco2/node_modules/glob2base/index.js:48:12)
    at module.exports (/Users/miguel/src/reco2/node_modules/glob2base/index.js:56:19)
    at Object.gs.createStream (/Users/miguel/src/reco2/node_modules/glob-stream/index.js:34:42)
    at /Users/miguel/src/reco2/node_modules/glob-stream/index.js:80:17
    at Array.map (native)
    at Object.gs.create (/Users/miguel/src/reco2/node_modules/glob-stream/index.js:79:29)
    at Gulp.src (/Users/miguel/src/reco2/node_modules/vinyl-fs/lib/src/index.js:33:23)
    at Gulp.<anonymous> (/Users/miguel/src/reco2/gulpfile.js:13:8)
    at module.exports (/Users/miguel/src/reco2/node_modules/orchestrator/lib/runTask.js:34:7)
@idflood
Copy link

idflood commented Aug 22, 2016

Same here, the error seems to be triggered by any gulp.src() call : /

@garethtalty
Copy link

garethtalty commented Aug 22, 2016

+1 Same error here, anyone found a workaround?

@enna
Copy link

enna commented Aug 22, 2016

Nope, try to debugging, but no idea. The error appears this morning after I cleaned all my node_modules repo and made a npm i in my project. :(

@sulmanen
Copy link

sulmanen commented Aug 22, 2016

Same here, debugging. gulp 3.9.1, node 4.5.0 LTS on OS X 10.11.6

@SparksFyz
Copy link

SparksFyz commented Aug 22, 2016

+1 same problem

windows os seems has not this problem.

@enna
Copy link

enna commented Aug 22, 2016

I got WARNS in my logs of npm i about deprecated minimatch version. Minimatch is used in many gulp modules. I am not sure it is related.

npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated lodash@1.0.2: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated graceful-fs@1.2.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN deprecated minimatch@0.2.12: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

@matthewnessworthy
Copy link

matthewnessworthy commented Aug 22, 2016

Same here:

TypeError: Cannot read property 'length' of undefined
    at flattenGlob (/Users/user/Sites/project/node_modules/glob2base/index.js:9:25)
    at setToBase (/Users/user/Sites/project/node_modules/glob2base/index.js:48:12)
    at module.exports (/Users/user/Sites/project/node_modules/glob2base/index.js:56:19)
    at Object.gs.createStream (/Users/user/Sites/project/node_modules/vinyl-fs/node_modules/glob-stream/index.js:34:42)
    at /Users/user/Sites/project/node_modules/vinyl-fs/node_modules/glob-stream/index.js:80:17
    at Array.map (native)
    at Object.gs.create (/Users/user/Sites/project/node_modules/vinyl-fs/node_modules/glob-stream/index.js:79:29)
    at Gulp.src (/Users/user/Sites/project/node_modules/vinyl-fs/lib/src/index.js:33:23)
    at module.exports (/Users/user/Sites/project/.build/tasks/javascript.js:11:17)
    at /Users/user/Sites/project/gulpfile.js:34:52
    at Array.map (native)
    at Gulp.<anonymous> (/Users/user/Sites/project/gulpfile.js:33:46)
    at module.exports (/Users/user/Sites/project/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/user/Sites/project/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/user/Sites/project/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/user/Sites/project/node_modules/orchestrator/index.js:134:8)

Triggered by the call gulp.src(options.src). options.src being a path string value

@joaomoreno
Copy link

joaomoreno commented Aug 22, 2016

Also hitting it in the build of Microsoft/vscode.

Seems to have been due to some npm dependency update...

joaomoreno referenced this issue in microsoft/vscode Aug 22, 2016
@martpie
Copy link

martpie commented Aug 22, 2016

I can confirm this, even with an empty task:

[12:02:25] Using gulpfile ~/dev/teleport-skin/skin-builder/gulpfile.js
[12:02:25] Starting 'default'...
[12:02:25] Starting 'test'...
[12:02:25] 'test' errored after 3.83 ms
[12:02:25] TypeError: Cannot read property 'length' of undefined
    at flattenGlob (/home/pierre/dev/teleport-skin/skin-builder/node_modules/glob2base/index.js:9:25)
    at setToBase (/home/pierre/dev/teleport-skin/skin-builder/node_modules/glob2base/index.js:48:12)
    at module.exports (/home/pierre/dev/teleport-skin/skin-builder/node_modules/glob2base/index.js:56:19)
    at Object.gs.createStream (/home/pierre/dev/teleport-skin/skin-builder/node_modules/glob-stream/index.js:34:42)
    at Object.gs.create (/home/pierre/dev/teleport-skin/skin-builder/node_modules/glob-stream/index.js:68:42)
    at Gulp.src (/home/pierre/dev/teleport-skin/skin-builder/node_modules/vinyl-fs/lib/src/index.js:33:23)
    at Gulp.<anonymous> (/home/pierre/dev/teleport-skin/skin-builder/gulpfile.js:93:17)
    at module.exports (/home/pierre/dev/teleport-skin/skin-builder/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/home/pierre/dev/teleport-skin/skin-builder/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/home/pierre/dev/teleport-skin/skin-builder/node_modules/orchestrator/index.js:214:10)

@callumacrae
Copy link
Member

callumacrae commented Aug 22, 2016

I'm guessing everyone with publish access to npm is asleep, but if we can figure out which dependency has broken, you can install the old version manually in your root package.json and gulp will use the old version, instead of the new version.

Out of interest, is anyone having this problem with gulp 4?

@enna: unrelated

@sulmanen
Copy link

sulmanen commented Aug 22, 2016

vinyl-fs dependency in gulp 3.9.1 is ^0.3.0.

cd node_modules/gulp
nano package.json
change vinyl-fs dep from ^0.3.0 to 2.4.3

node_modules/gulp/npm install .
Get errors, but after updating vinyl-fs, gulp 3.9.1 seems to work.

verify with

npm ls vinyl-fs
thinglink@0.0.1 /Users/sulmanen/work/site
└─┬ gulp@3.9.1
└── vinyl-fs@2.4.3

Seems to be a glob2base issue, and there's a pull there https://github.com/contra/glob2base/pull/9/files

@Moinax
Copy link

Moinax commented Aug 22, 2016

I see another strange thing.

From today, if I log a simple config array, I got "Circular" instead of simple array of strings

{ js: 
   { src: [ [Circular] ],
     watch: [ [Circular] ],
     dest: 'web/public/build/js',
     filename: 'bundle.js' },
  css: 
   { src: 
      [ 'node_modules/normalize.css/normalize.css',
        'node_modules/jquery-bar-rating/dist/themes/css-stars.css',
        'web/public/src/sass/client.scss' ],
     watch: [ [Circular] ],
     dest: 'web/public/build/css',
     filename: 'bundle.css' },
  app: { watch: [ 'web/**/*', '!web/public/**/*' ] } }

Instead of

{
    js: {
        src: [
            'web/public/src/js/client.js'
        ],
        watch: [
            'web/public/src/js/**/*.@(js|json|html)'
        ],
        dest: 'web/public/build/js',
        filename: 'bundle.js'
    },
    css: {
        src: [
            'node_modules/normalize.css/normalize.css',
            'node_modules/jquery-bar-rating/dist/themes/css-stars.css',
            'web/public/src/sass/client.scss'
        ],
        watch: [
            'web/public/src/**/*.scss'
        ],
        dest: 'web/public/build/css',
        filename: 'bundle.css'
    },
    app: {
        watch: [
            'web/**/*',
            '!web/public/**/*'
        ]
    }
}

@joshbalfour
Copy link

@sulmanen's fix didn't work for me

@callumacrae
Copy link
Member

@sulmanen: Given that there haven't been any recent updates to it or any or its single dependency, I doubt it's an issue with that module

@sulmanen
Copy link

@callumacrae you're right, seems more like a symptom.

@sulmanen
Copy link

@joshbalfour it's a bit hackish but my ci is running now. Verify with

npm ls vinyl-fs
thinglink@0.0.1 /Users/sulmanen/work/site
└─┬ gulp@3.9.1
└── vinyl-fs@2.4.3

@joshbalfour
Copy link

@sulmanen I've verified and am still seeing the issue, will be interested to see the results of your CI

├─┬ gulp@3.9.1
│ └── vinyl-fs@2.4.3 
└── vinyl-fs@2.4.3 

@callumacrae
Copy link
Member

(my bad, wrong button)

@vividuaelsaphe
Copy link

I am having the same problem from a couple of hours ago. I don't know how to fix this, any good news?

@cfeeling
Copy link

It seems a issue about minimatch in glob. In our case, the property named set of minimatch in glob is empty now, but glob2base expected it should be an array with one element at least
After adding output before usage of minimatch.set in glob2base, I got the minimatch object as below:

Minimatch {
  options: 
   { read: true,
     buffer: true,
     cwd: '/home/cfeeling/Projects/frontend-web',
     dot: false,
     silent: true,
     nonull: false,
     cwdbase: false },
  set: [],
  pattern: '/home/cfeeling/Projects/frontend-web/build',
  regexp: null,
  negate: false,
  comment: false,
  empty: false,
  globSet: [ [Circular] ],
  globParts: 
   [ [ '',
       'home',
       'cfeeling',
       'Projects',
       'frontend-web',
       'build' ] ] }

@joshbalfour
Copy link

@cfeeling could yocontra/glob2base#11 fix this?

@sulmanen
Copy link

@joshbalfour

npm-install:
     [echo] If this fails, make sure you have 'npm' in your path.
     [exec] - source-map@0.2.0 node_modules/less/node_modules/source-map
     [exec] thinglink@0.0.1 /mnt/jenkins/su-new-svg-icons-se/workspace
     [exec] └── less@2.5.1 
     [exec] 
     [exec] npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
     [exec] npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
     [exec] npm WARN thinglink@0.0.1 license should be a valid SPDX license expression

babel:
     [exec] [10:43:41] Using gulpfile /mnt/jenkins/su-new-svg-icons-se/workspace/gulpfile.js
     [exec] [10:43:41] Starting 'babel'...

translations2ascii:
[native2ascii] Converting 13 files from /mnt/jenkins/su-new-svg-icons-se/workspace/src/main/resources/i18n to /mnt/jenkins/su-new-svg-icons-se/workspace/src/main/resources/i18n

used to fail with gulp babel

@cfeeling
Copy link

@joshbalfour I will try it ASAP, plz wait a moment

@cfeeling
Copy link

@joshbalfour It just disable the error, but any actions followed it can not be executed anymore

@jjaybrown
Copy link

@joshbalfour @cfeeling it will silence the error, but still fail as undefined is passed into it. The issue is around why undefined is being passed into the method

@joshbalfour
Copy link

@callumacrae I'm still seeing the issue with

gousto2frontend@0.0.0 /Users/joshuabalfour/Projects/Gousto2-FrontEnd/src
├─┬ gulp@3.9.1
│ └── UNMET DEPENDENCY vinyl-fs@^0.3.0
└── vinyl-fs@2.4.3 

@cfeeling
Copy link

@Delta98 I agree it, the core is why minimatch.set is empty now instead of an array with one element at least.

@joaomoreno
Copy link

joaomoreno commented Aug 22, 2016

It makes no sense at all... but when we (Microsoft/vscode) comment out this line, which requires gulp-cssnano, the error goes away. It's as if some dependency within gulp-cssnano interferes with some dependency within gulp.

@jjaybrown
Copy link

@joaomoreno we also use gulp-cssnano but I don't think it's the root issue.

@joaomoreno
Copy link

joaomoreno commented Aug 22, 2016

@Delta98 Give it a try. It's highly reproducible for me.

@dortamiguel
Copy link
Author

@Delta98 commenting gulp-cssnano fixes it for me

@Moinax
Copy link

Moinax commented Aug 22, 2016

I just tried to remove the use of cssnano @joaomoreno and it fixed the problem on my side too.

@joshbalfour
Copy link

@Delta98 commenting gulp-cssnano fixes it for me also

@Phalconline
Copy link

@Delta98 gulp-cssnano fixes it for me also too

@cfeeling
Copy link

@Delta98 I think gulp-cssnano is not the core.
I did not use gulp-cssnano, only gulp and gulp-clean was used in my case, but I also met this problem.

@jjaybrown
Copy link

@joaomoreno yeah, it stops the error, but something must have changed within the package, or cascades through that plugin. As @cfeeling says it's not used on his project.

@Phalconline
Copy link

@cfeeling I don't think so, bcs gulp-cssnano has last update 4 month ago

@julia-utenkova
Copy link

Having the same issue here...
I don't have gulp-cssnano in my gulpfile config, so I still get the error..

@joshbalfour
Copy link

running npm install in gulp-cssnano also fixed this for me

@jjaybrown
Copy link

Looking at cssnano deps it uses the following:
"cssnano": "^3.0.0",
"gulp-util": "^3.0.6",
"object-assign": "^4.0.1",
"vinyl-sourcemaps-apply": "^0.2.1"

I think there is a common strand which might be the root cause, @cfeeling are you using any of these packages or are you uses a package that uses these?

@TheSpyder
Copy link

This has been fixed upstream, delete node_modules and reinstall should work now

@jjaybrown
Copy link

@TheSpyder what was the package?

@TheSpyder
Copy link

The bug was in a new dependency of postcss-calc, used by cssnano. It had a broken polyfill of Array.prototype.indexOf.

@cfeeling
Copy link

@Delta98 lots of packages are using those four packages

@julia-utenkova
Copy link

Now it works! Many thanks @TheSpyder ! You are my hero! <3

@TheSpyder
Copy link

For the curious, bug reference MoOx/reduce-css-calc#13

@callumacrae
Copy link
Member

callumacrae commented Aug 22, 2016

Good stuff. Thanks, @TheSpyder.

The actual fix is here, caused by a library globally patching Array.prototype.indexOf with a dodgy comparison, and breaking it: bugwheels94/math-expression-evaluator#2

Closing this issue now.

@cfeeling
Copy link

@TheSpyder It works well, u r also my hero

@vividuaelsaphe
Copy link

Thanks for fixing it!!!!

@TheSpyder
Copy link

yeah, the chain is about 5 dependencies long. Didn't think I needed to draw too much attention to the underlying issue :)

@callumacrae
Copy link
Member

Please react with the 👍 or 🎉 emoji on one of @TheSpyder's messages instead of writing an appreciative comment, thank you! There are 18 participants in this thread, and you are sending all of them notifications / emails.

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