gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

Fatal error: Cannot read property 'files' of undefined #548

Open zeroerrequattro opened 6 years ago

zeroerrequattro commented 6 years ago

I use grunt watch with the following modules to minify the code in my website:

Everytime I launch grunt watch and modify some file, i got this error:

Fatal error: Cannot read property 'files' of undefined

Even with grunt watch --verbose I don't get any other useful info than the error If I launch the tasks separately (eg. grunt uglify) they work with no problems.

Here's the package.json:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    htmlmin: {
      build: {
        options: {
          removeComments: true,
          collapseWhitespace: true,
          ignoreCustomFragments: [
            /\{\{[\s\S](.*?)\}\}/,
            /\{\%[\s\S](.*?)\%\}/,
            /<\?[\s\S]*?\?>/
          ]
        },
        files: [
          {
            expand: true,
            cwd: 'dev/html/layout',
            src: ['*.html'],
            dest: 'theme/layout',
            ext: '.liquid',
            extDot: 'last'
          },
          {
            expand: true,
            cwd: 'dev/html/snippets',
            src: ['*.html'],
            dest: 'theme/snippets',
            ext: '.liquid',
            extDot: 'last'
          },
          {
            expand: true,
            cwd: 'dev/html/templates',
            src: ['*.html'],
            dest: 'theme/templates',
            ext: '.liquid',
            extDot: 'last'
          }
        ]
      }
    },
    uglify: {
      options: {
        mangle: false,
        //banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */'
      },
      dest: {
        files: {
          'theme/assets/vendors.min.js': [
            'dev/js/vendor/jquery.min.js',
            'dev/js/vendor/bootstrap.min.js',
            'dev/js/vendor/jquery.scrollto.js',
            'dev/js/vendor/owl.carousel.min.js',
            'dev/js/vendor/waypoint.min.js'
          ],
          'theme/assets/function-data.min.js.liquid': [ 'dev/js/function-data.js' ],
          'theme/assets/function-effect.min.js.liquid': [ 'dev/js/function-effect.js' ],
          'theme/assets/related-items.min.js.liquid': [
            'dev/js/related-items.js'
          ],
          'theme/assets/function-countries.min.js.liquid': [
            'dev/js/function-countries.js'
          ]
        }
      }
    },
    compass: {
      dist: {
        options: {
          config: 'compass.rb',
          outputStyle: 'compressed',
          environment: 'production',
          specify: [
            'dev/scss/account.scss',
            'dev/scss/cart.scss',
            'dev/scss/checkout.scss',
            'dev/scss/collections.scss',
            'dev/scss/home.scss',
            'dev/scss/landings.scss',
            'dev/scss/main.scss',
            'dev/scss/page-freelancer.scss',
            'dev/scss/page-shop-instagram.scss',
            'dev/scss/page-special-collection01.scss',
            'dev/scss/page-static.scss',
            'dev/scss/page-weddings.scss',
            'dev/scss/product.scss',
            'dev/scss/referral.scss'
          ],

          relativeAssets: false,
          noLineComments: false,
          sourcemap: false
        }
      }
    },
    watch: {
      sass: {
        files: ['dev/scss/**'],
        tasks: ['compass']
      },
      js: {
        files: ['dev/js/**'],
        tasks: ['uglify']
      },
      html: {
        files: ['dev/html/**'],
        tasks: ['htmlmin']
      }
    }
  });

  // Load the plugins that provides the tasks.
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-compass');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task(s).
  grunt.registerTask('default', ['watch']);
  grunt.registerTask('build', ['compass','uglify','htmlmin']);
};

Here's the environment I'm working with: MacOS 10.12.6 node@8.6.0 npm@5.4.2

zeroerrequattro commented 6 years ago

Any news?

zeroerrequattro commented 6 years ago

Did I set something wrong? Is something related to some other module? Is this module deprecated?

zeroerrequattro commented 6 years ago

Somebody can please help me with this? It's almost 4 months and nobody told me anything.

I updated the system, reinstalled the modules but the problem persist, I keep receiving the message:

Fatal error: Cannot read property 'files' of undefined

The environment is: MacOS 10.13.3 node@v8.7.0 npm@5.6.0

starryeyez024 commented 4 years ago

I am getting the same error :(