yeoman / generator-angular

Yeoman generator for AngularJS
http://yeoman.io
5.73k stars 1.44k forks source link

Gulp:build-client error (File not found with singular glob) with Generator-Angular #1412

Closed psujit closed 7 years ago

psujit commented 7 years ago

When I try to run gulp:build-client task I get an error (File not found with singular glob), see Error Stack below. I have found out the problem but I am unsure how to solve it. In the First line of the error, it is looking for bower_components directly in my base folder(Projects) rather than the project folder(MyProject). Please let me know how this issue can be solved.

Using gulpfile ~\Desktop\Projects\MyProject\gulpfile.js
Starting 'clean:dist'...
Starting 'install'...
Finished 'install' after 416 ms
Starting 'bower'...
Finished 'clean:dist' after 657 ms
gulp-inject 14 files into index.html.
gulp-inject 2 files into index.html.
gulp-inject 61 files into index.html.
Finished 'bower' after 634 ms
Starting 'build'...
Starting 'images'...
Starting 'html'...
Starting 'copy:extras'...
Starting 'copy:fonts'...
Starting 'copy:favicon'...
Starting 'install'...
Starting 'styles'...
Finished 'build' after 283 ms
Starting 'default'...
Finished 'default' after 29 μs
(node:10104) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
Finished 'copy:extras' after 43 ms
Finished 'styles' after 41 ms
Finished 'install' after 91 ms
Starting 'bower'...
Finished 'copy:favicon' after 143 ms
Finished 'images' after 492 ms
gulp-inject 14 files into index.html.
gulp-inject 2 files into index.html.
Finished 'copy:fonts' after 547 ms
Finished 'html' after 567 ms
gulp-inject 61 files into index.html.
Finished 'bower' after 567 ms
Starting 'client:build'...
events.js:182
      throw er; // Unhandled 'error' event

Error: Error: File not found with singular glob: C:\Users\Sujit\Desktop\Projects\bower_components\semantic-ui\dist\semantic.css
    at DestroyableTransform.<anonymous> (C:\Users\Sujit\Desktop\Projects\MyProject\node_modules\gulp-useref\index.js:65:28)
    at emitOne (events.js:120:20)
    at DestroyableTransform.emit (events.js:210:7)
    at emitOne (events.js:120:20)
    at Through2.emit (events.js:210:7)
    at OrderedStreams.<anonymous> (C:\Users\Sujit\Desktop\Projects\MyProject\node_modules\gulp-useref\node_modules\glob-stream\index.js:140:20)
    at emitOne (events.js:115:13)
    at OrderedStreams.emit (events.js:210:7)
    at emitOne (events.js:115:13)
    at DestroyableTransform.emit (events.js:210:7)
    at Glob.<anonymous> (C:\Users\Sujit\Desktop\Projects\MyProject\node_modules\gulp-useref\node_modules\glob-stream\index.js:40:16)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at Glob.emit (events.js:210:7)
    at Glob._finish (C:\Users\Sujit\Desktop\Projects\MyProject\node_modules\gulp-useref\node_modules\glob-stream\node_modules\glob\glob.js:172:8)
    at done (C:\Users\Sujit\Desktop\Projects\MyProject\node_modules\gulp-useref\node_modules\glob-stream\node_modules\glob\glob.js:159:12)

Please find below the results of yo --version && echo %PATH% %NODE_PATH% && node -e "console.log(process.platform, process.versions)" && type Gulpfile.js

2.0.0
C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Lenovo\FusionEngine;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Users\Sujit\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Go\bin;C:\TDM-GCC-64\bin;C:\Program Files\Git\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Minimal ADB and Fastboot;C:\Program Files (x86)\Skype\Phone\;C:\Users\Sujit\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Users\Sujit\AppData\Local\Microsoft\WindowsApps;C:\Users\Sujit\AppData\Roaming\nvm;C:\Program Files\nodejs %NODE_PATH%
win32 { http_parser: '2.7.0',
  node: '8.1.2',
  v8: '5.8.283.41',
  uv: '1.12.0',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  openssl: '1.0.2l',
  icu: '59.1',
  unicode: '9.0',
  cldr: '31.0.1',
  tz: '2017b' }
'use strict';

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var openURL = require('open');
var lazypipe = require('lazypipe');
var rimraf = require('rimraf');
var wiredep = require('wiredep').stream;
var runSequence = require('run-sequence');
var bower = require('bower');
var angularFilesort = require('gulp-angular-filesort');
var inject = require('gulp-inject');
var naturalSort = require('gulp-natural-sort');
var bowerFiles = require('main-bower-files');
var es = require('event-stream');
var ghPages = require('gulp-gh-pages');

//app directory structor
var yeoman = {
  app: require('./bower.json').appPath || 'app',
  dist: 'dist',
  temp: '.tmp',
  test: 'test'
};

// for sources
var paths = {
  scripts: [yeoman.app + '/scripts/**/*.js'],
  styles: [yeoman.app + '/styles/**/*.scss'],
  test: ['test/spec/**/*.js'],
  testRequire: [
    'bower_components/angular/angular.js',
    'bower_components/angular-mocks/angular-mocks.js',
    'bower_components/angular-resource/angular-resource.js',
    'bower_components/angular-cookies/angular-cookies.js',
    'bower_components/angular-sanitize/angular-sanitize.js',
    'bower_components/angular-route/angular-route.js',
    'bower_components/angular-animate/angular-animate.js',
    'bower_components/angular-touch/angular-touch.js',
    'bower_components/angular-ui-sortable/sortable.js',
    'bower_components/angular-ui-router/release/angular-ui-router.js',
    'bower_components/angular-local-storage/dist/angular-local-storage.js',
    'test/mock/**/*.js',
    'test/spec/**/*.js'
  ],
  karma: yeoman.test + '/karma.conf.js',
  views: {
    main: yeoman.app + '/index.html',
    bowermain: yeoman.temp + '/index.html',
    files: [yeoman.app + '/views/**/*.html']
  }
};

////////////////////////
// Reusable pipelines //
////////////////////////

var lintScripts = lazypipe()
.pipe($.jshint, '.jshintrc')
.pipe($.jshint.reporter, 'jshint-stylish');

var styles = lazypipe()
.pipe($.autoprefixer, 'last 1 version')
.pipe(gulp.dest, '.tmp/styles');
///////////
// Tasks //
///////////

gulp.task('styles', function () {
  return gulp.src(paths.styles)
    .pipe(styles());
});

gulp.task('lint:scripts', function () {
  return gulp.src(paths.scripts)
    .pipe(lintScripts());
});

gulp.task('clean:tmp', function (cb) {
  rimraf(yeoman.temp, cb);
});

gulp.task('start:client', ['start:server', 'styles', 'lint:scripts'], function () {
  openURL('http://localhost:9000');
});

gulp.task('start:server', function() {
  $.connect.server({
    root:[yeoman.temp, yeoman.app],
    livereload:true,
    port: 9000,
    middleware:function(connect, opt){
      return [['/bower_components',
        connect["static"]('./bower_components')],['/other_components', connect["static"]('./other_components')]]
    }
  });
});

gulp.task('start:server:test', function() {
  $.connect.server({
    root: [yeoman.test, yeoman.app, yeoman.temp],
    livereload: true,
    port: 9001,
    middleware:function(connect, opt){
      return [['/bower_components', connect["static"]('./bower_components')],
        ['/other_components', connect["static"]('./other_components')]
    ]}
  });
});

gulp.task('watch', function () {
  $.watch(paths.styles)
    .pipe($.plumber())
    .pipe(styles())
    .pipe($.connect.reload())

  $.watch(paths.views.files)
    .pipe($.plumber())
    .pipe($.connect.reload())

  $.watch(paths.views.main)
    .pipe($.plumber())
    .pipe($.connect.reload())

  $.watch(paths.scripts)
    .pipe($.plumber())
    .pipe(lintScripts())

  $.watch(paths.test)
    .pipe($.plumber())

  gulp.watch('bower.json', ['bower']);
});

gulp.task('serve', function (cb) {
  runSequence('clean:tmp',
    ['bower'],
    ['lint:scripts'],
    ['start:client'],
    'watch', cb);
});

gulp.task('serve:prod', function() {
  $.connect.server({
    root:[yeoman.dist],
    livereload:{
      port:81
    },
    port: 80,
    middleware:function(connect, opt){
      return [['/bower_components', connect["static"]('./bower_components')],
        ['/other_components', connect["static"]('./other_components')]
    ]}
  });
});

gulp.task('test', ['start:server:test'], function () {
  var testToFiles = paths.testRequire.concat(paths.scripts, paths.test);
  return gulp.src(testToFiles)
    .pipe($.karma({
      configFile: paths.karma,
      action: 'watch'
    }));
});

// inject bower components
gulp.task('bower',['install'], function () {
  var bowerStreamJS = gulp.src(bowerFiles('**/*.js'));
  var bowerStreamCSS = gulp.src(bowerFiles('**/*.css'));
  var appStreamJS = gulp.src(['./other_components/**/**/*.js'])
    .pipe(angularFilesort());
  return gulp.src(paths.views.main)
    .pipe(
      inject(bowerStreamJS, {relative: true, name: 'bower'})
    )
    // send bower bower css
    .pipe(
      inject(bowerStreamCSS, {relative: true, name: 'bower'})
    )
    // send app scripts
    .pipe(
      inject(appStreamJS, {relative: true})
    )
  .pipe(gulp.dest(yeoman.temp));
});

///////////
//Deploy//
/////////

gulp.task('deploy', function() {
  return gulp.src('./dist/**/*')
    .pipe(ghPages());
});

///////////
// Build //
///////////

gulp.task('clean:dist', function (cb) {
  rimraf(yeoman.dist, cb);
});

gulp.task('client:build', ['bower', 'html', 'styles'], function () {
  var jsFilter = $.filter('**/*.js');
  var cssFilter = $.filter('**/*.css');

  return gulp.src(paths.views.bowermain)
    .pipe($.useref({searchPath: [yeoman.app, yeoman.temp]}))
    .pipe(jsFilter)
    .pipe($.ngAnnotate())
    .pipe($.uglify())
    .pipe(jsFilter.restore())
    .pipe(cssFilter)
    .pipe($.minifyCss({cache: true}))
    .pipe(cssFilter.restore())
    .pipe(gulp.dest(yeoman.dist));
});

gulp.task('html', function () {
  return gulp.src(yeoman.app + '/views/**/*')
    .pipe(gulp.dest(yeoman.dist + '/views'));
});

gulp.task('images', function () {
  return gulp.src(yeoman.app + '/images/**/*')
    .pipe($.cache($.imagemin({
        optimizationLevel: 5,
        progressive: true,
        interlaced: true
    })))
    .pipe(gulp.dest(yeoman.dist + '/images'));
});

gulp.task('copy:extras', function () {
  return gulp.src(yeoman.app + '/*/.*', { dot: true })
    .pipe(gulp.dest(yeoman.dist));
});

gulp.task('copy:fonts', function () {
  return gulp.src('./bower_components/bootstrap/dist/fonts/**/*')
    .pipe(gulp.dest(yeoman.dist + '/fonts'));
});

gulp.task('copy:favicon', function () {
  return gulp.src(yeoman.app + '/favicon.ico')
    .pipe(gulp.dest(yeoman.dist));
});

gulp.task('install', function(cb){
  bower.commands.install([], {save: true}, {})
    .on('end', function(installed){
      cb(); // notify gulp that this task is finished
    });
});

gulp.task('build', ['clean:dist', 'bower'], function () {
  runSequence(['images', 'html', 'copy:extras', 'copy:fonts', 'copy:favicon', 'client:build']);
});

gulp.task('default', ['build']);
psujit commented 7 years ago

Turns out that creating a custom injector for bower components was causing the issue. Resolved it by using the default bower injector. Thanks!