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

Invalid glob argument when building using the Nunjucks recipe #518

Closed
ghost opened this issue May 12, 2016 · 4 comments
Closed

Invalid glob argument when building using the Nunjucks recipe #518

ghost opened this issue May 12, 2016 · 4 comments

Comments

@ghost
Copy link

ghost commented May 12, 2016

I enter gulp and below is the error log that is displayed on my terminal:

[15:03:45] Using gulpfile /var/www/html/cleveland-latest/gulpfile.js
[15:03:45] Starting 'clean'...
[15:03:45] Finished 'clean' after 9.43 ms
[15:03:45] Starting 'default'...
[15:03:45] Starting 'views'...
[15:03:45] Starting 'styles'...
[15:03:46] Starting 'scripts'...
[15:03:46] Starting 'images'...
[15:03:46] Starting 'fonts'...
[15:03:46] Starting 'extras'...
[15:03:46] Finished 'default' after 488 ms
[15:03:46] Finished 'images' after 146 ms
[15:03:46] Finished 'views' after 640 ms
[15:03:46] Finished 'styles' after 579 ms
[15:03:46] Finished 'scripts' after 448 ms
[15:03:46] Starting 'html'...
[15:03:46] unicorn: .tmp/index.html
/var/www/html/cleveland-latest/node_modules/gulp-useref/node_modules/vinyl-fs/lib/src/index.js:32
    throw new Error('Invalid glob argument: ' + glob);
    ^

Error: Invalid glob argument: 
    at Object.src (/var/www/html/cleveland-latest/node_modules/gulp-useref/node_modules/vinyl-fs/lib/src/index.js:32:11)
    at DestroyableTransform.module.exports.addAssetsToStream (/var/www/html/cleveland-latest/node_modules/gulp-useref/lib/streamManager.js:85:23)
    at /var/www/html/cleveland-latest/node_modules/gulp-useref/lib/streamManager.js:142:47
    at Array.forEach (native)
    at DestroyableTransform.module.exports.processAssets (/var/www/html/cleveland-latest/node_modules/gulp-useref/lib/streamManager.js:133:19)
    at DestroyableTransform.module.exports.processFilesAndAssets (/var/www/html/cleveland-latest/node_modules/gulp-useref/lib/streamManager.js:172:39)
    at /var/www/html/cleveland-latest/node_modules/gulp-useref/lib/streamManager.js:182:47
    at Stream.<anonymous> (/var/www/html/cleveland-latest/node_modules/event-stream/index.js:306:20)
    at _end (/var/www/html/cleveland-latest/node_modules/through/index.js:65:9)
    at Stream.stream.end (/var/www/html/cleveland-latest/node_modules/through/index.js:74:5)
    at DestroyableTransform.onend (/var/www/html/cleveland-latest/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:495:10)
    at DestroyableTransform.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at DestroyableTransform.emit (events.js:166:7)
    at DestroyableTransform.module.exports.transformFunction [as _transform] (/var/www/html/cleveland-latest/node_modules/gulp-useref/lib/streamManager.js:188:39)
    at DestroyableTransform.Transform._read (/var/www/html/cleveland-latest/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)

I have edited gulpfile with the nunjucks recipe:


// generated on 2016-05-12 using generator-webapp 2.1.0
const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const browserSync = require('browser-sync');
const del = require('del');
const wiredep = require('wiredep').stream;

const $ = gulpLoadPlugins();
const reload = browserSync.reload;

gulp.task('styles', () => {
  return gulp.src('app/styles/*.scss')
    .pipe($.plumber())
    .pipe($.sourcemaps.init())
    .pipe($.sass.sync({
      'outputStyle': 'expanded',
      'precision': 10,
      'includePaths': ['.']
    }).on('error', $.sass.logError))
    .pipe($.autoprefixer({'browsers': ['> 1%', 'last 2 versions', 'Firefox ESR']}))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/styles'))
    .pipe(reload({'stream': true}));
});

gulp.task('scripts', () => {
  return gulp.src('app/scripts/**/*.js')
    .pipe($.plumber())
    .pipe($.sourcemaps.init())
    .pipe($.babel())
    .pipe($.sourcemaps.write('.'))
    .pipe(gulp.dest('.tmp/scripts'))
    .pipe(reload({'stream': true}));
});

gulp.task('views', () => {
  return gulp.src('app/*.njk')
  .pipe($.nunjucksRender({
      'path': 'app'
    }))
    .pipe(gulp.dest('.tmp'));
});


gulp.task('html', ['views', 'styles', 'scripts'], () => {
  return gulp.src(['app/*.html', '.tmp/*.html'])
  .pipe($.debug({'title': 'unicorn:'}))
    .pipe($.useref({'searchPath': ['.tmp', 'app', '.']}))
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.cssnano({'safe': true, 'autoprefixer': false})))
    .pipe($.if('*.html', $.htmlmin({'collapseWhitespace': true})))
    .pipe(gulp.dest('dist'));
});

gulp.task('images', () => {
  return gulp.src('app/images/**/*')
    .pipe($.cache($.imagemin({
      'progressive': true,
      'interlaced': true,
      // don't remove IDs from SVGs, they are often used
      // as hooks for embedding and styling
      'svgoPlugins': [{'cleanupIDs': false}]
    })))
    .pipe(gulp.dest('dist/images'));
});

gulp.task('fonts', () => {
  return gulp.src(require('main-bower-files')('**/*.{eot,svg,ttf,woff,woff2}', function (err) {})
    .concat('app/fonts/**/*'))
    .pipe(gulp.dest('.tmp/fonts'))
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('extras', () => {
  return gulp.src([
    'app/*.*',
    '!app/*.html',
    '!app/*.njk'
  ], {
    'dot': true
  }).pipe(gulp.dest('dist'));
});

gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

gulp.task('serve', ['views', 'styles', 'scripts', 'fonts'], () => {
  browserSync({
    'notify': false,
    'port': 9000,
    'server': {
      'baseDir': ['.tmp', 'app'],
      'routes': {
        '/bower_components': 'bower_components'
      }
    }
  });

  gulp.watch([
    'app/*.html',
    '.tmp/*.html',
    'app/images/**/*',
    '.tmp/fonts/**/*'
  ]).on('change', reload);

  gulp.watch('app/**/*.html', ['views']);
  gulp.watch('app/**/*.njk', ['views']);
  gulp.watch('app/styles/**/*.scss', ['styles']);
  gulp.watch('app/scripts/**/*.js', ['scripts']);
  gulp.watch('app/fonts/**/*', ['fonts']);
  gulp.watch('bower.json', ['wiredep', 'fonts']);
});

gulp.task('serve:dist', () => {
  browserSync({
    'notify': false,
    'port': 9000,
    'server': {
      'baseDir': ['dist']
    }
  });
});

gulp.task('serve:test', ['scripts'], () => {
  browserSync({
    'notify': false,
    'port': 9000,
    'ui': false,
    'server': {
      'baseDir': 'test',
      'routes': {
        '/scripts': '.tmp/scripts',
        '/bower_components': 'bower_components'
      }
    }
  });

  gulp.watch('app/scripts/**/*.js', ['scripts']);
  gulp.watch('test/spec/**/*.js').on('change', reload);
  gulp.watch('test/spec/**/*.js');
});

// inject bower components
gulp.task('wiredep', () => {
  gulp.src('app/styles/*.scss')
    .pipe(wiredep({
      'ignorePath': /^(\.\.\/)+/
    }))
    .pipe(gulp.dest('app/styles'));

  gulp.src('app/layouts/*.njk')
    .pipe(wiredep({
      'exclude': ['bootstrap-sass'],
      'ignorePath': /^(\.\.\/)*\.\./,
      'fileTypes': {
         'njk': {
          'block': /(([ \t]*)<!--\s*bower:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/gi,
          'detect': {
            'js': /<script.*src=['"]([^'"]+)/gi,
            'css': /<link.*href=['"]([^'"]+)/gi
          },
          'replace': {
            'js': '<script src="{{filePath}}"></script>',
            'css': '<link rel="stylesheet" href="{{filePath}}" />'
          }
        }
      }
    }))
    .pipe(gulp.dest('app/layouts'));
});

gulp.task('build', ['html', 'images', 'fonts', 'extras'], () => {
  return gulp.src('dist/**/*').pipe($.size({'title': 'build', 'gzip': true}));
});

gulp.task('default', ['clean'], () => {
  gulp.start('build');
});

Node version:
4.4.4

NPM version
3.8.9

@silvenon silvenon changed the title throw new Error('Invalid glob argument: ' + glob); when running gulp Invalid glob argument when building using the Nunjucks recipe May 12, 2016
@silvenon silvenon added the docs label Oct 2, 2016
@silvenon
Copy link
Member

silvenon commented Nov 6, 2016

@srahulprdxn hey! I tried following the recipe myself and everything worked. I'm pretty sure that in your default.njk (or whatever your layout file is called) between comment blocks you are referencing a file which doesn't exist, so gulp-useref crashes. Could you also paste your .njk templates? Did this happen on a fresh install? Did you modify anything else than what the recipe instructed?

@silvenon
Copy link
Member

Closing due to inactivity. I will gladly reopen when we get new info.

@denysbutenko
Copy link

denysbutenko commented Apr 14, 2017

I had the same issue when tried to include external (from cdn) stylesheets and scripts in gulp-useref sections.

An example:

<!-- build:css styles/vendor.css -->
<!-- bower:css -->
<!-- endbower -->
<link href="https://api.mapbox.com/mapbox-gl-js/v0.35.1/mapbox-gl.css" rel="stylesheet" />
<!-- endbuild -->

@silvenon
Copy link
Member

@denysbutenko AFAIK that won't work, useref won't download remote files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants