title: Grunt watch warning: EPERM, operation not permitted
body: <p>I have a very annoying problem with gruntjs and <code>grunt-contrib-watch</code> plugin. After some time, I can not define, it may be half an hour or two hours of work (it's random) the console spits out this error:</p>
  
  <pre><code>Running "watch" task
  Waiting...Warning: EPERM, operation not permitted 'C:\dev\project\app\index.html~RF97bf99.TMP'
  </code></pre>
  
  <p>it repeats ~50 times, and next this:</p>
  
  <pre><code>Warning: An error occurred while processing a template (An error occurred while processing a templat
  e (Maximum call stack size exceeded).).
  Warning: An error occurred while processing a template (An error occurred while processing a templat
  e (An error occurred while processing a template (Maximum call stack size exceeded).).).
  Warning: An error occurred while processing a template (An error occurred while processing a templat
  e (An error occurred while processing a template (An error occurred while processing a template (Max
  imum call stack size exceeded).).).).
  Warning: An error occurred while processing a template (An error occurred while processing a templat
  e (An error occurred while processing a template (An error occurred while processing a template (An
  error occurred while processing a template (Maximum call stack size exceeded).).).).).
  </code></pre>
  
  <p>My Grunfile.js:</p>
  
  <pre><code>'use strict';
  
  module.exports = function (grunt) {
  
      // Load all grunt tasks
      require('load-grunt-tasks')(grunt);
      // Show elapsed time at the end
      require('time-grunt')(grunt);
  
      grunt.initConfig({
          // Project settings
          project: {
              app: 'app',
              dist: 'dist'
          },
          bootstrap: {
              src: 'bower_components/sass-bootstrap',
              pkg: grunt.file.readJSON('bower_components/sass-bootstrap/package.json'),
              banner: '/*!\n' +
                      ' * Bootstrap v&lt;%= bootstrap.pkg.version %&gt; by @fat and @mdo\n' +
                      ' * Copyright &lt;%= grunt.template.today("yyyy") %&gt; &lt;%= bootstrap.pkg.author %&gt;\n' +
                      ' * Licensed under &lt;%= _.pluck(bootstrap.pkg.licenses, "url").join(", ") %&gt;\n' +
                      ' *\n' +
                      ' * Designed and built with all the love in the world by @mdo and @fat.\n' +
                      ' */\n\n',
              jqueryCheck: 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery") }\n\n'
          },
          watch: {
              sass: {
                  files: ['&lt;%= project.app %&gt;/sass/{,*/}*.scss'],
                  tasks: ['sass:dev', 'autoprefixer'],
                  options: {
                      spawn: false,
                      livereload: true
                  },
              },
              js: {
                  files: [
                      '&lt;%= project.app %&gt;/js/{,*/}*.js',
                      '!&lt;%= project.app %&gt;/js/vendor/{,*/}*.js',
                      '!&lt;%= project.app %&gt;/js/plugins/{,*/}*.js'
                  ],
                  options: {
                      livereload: true
                  }
              },
              livereload: {
                  options: {
                      livereload: '&lt;%= connect.options.livereload %&gt;'
                  },
                  files: [
                      '&lt;%= project.app %&gt;/{,*/}*.html',
                      '&lt;%= project.app %&gt;/css/{,*/}*.css',
                      '&lt;%= project.app %&gt;/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}'
                  ]
              }
          },
          connect: {
              options: {
                  port: 9000,
                  livereload: 35729,
                  // Change this to '0.0.0.0' to access the server from outside
                  hostname: 'localhost'
              },
              livereload: {
                  options: {
                      open: true,
                      base: '&lt;%= project.app %&gt;'
                  }
              },
              dist: {
                  options: {
                      open: true,
                      base: '&lt;%= project.dist %&gt;',
                      livereload: false
                  }
              }
          },
          sass: {
              options: {
                  includePaths: ['&lt;%= bootstrap.src %&gt;/lib/']
              },
              dev: {
                  files: {
                      '&lt;%= project.app %&gt;/css/app.css': '&lt;%= project.app %&gt;/sass/app.scss'
                  }
              },
              dist: {
                  files: {
                      '&lt;%= project.app %&gt;/css/app.css': '&lt;%= project.app %&gt;/sass/app.scss'
                  }
              }
          },
          autoprefixer: {
              options: {
                  browsers: ['last 2 version']
              },
              dist: {
                  files: [{
                      expand: true,
                      cwd: '&lt;%= project.app %&gt;/css/',
                      src: '{,*/}*.css',
                      dest: '&lt;%= project.app %&gt;/css/'
                  }]
              }
          },
          concat: {
              options: {
                  nonull: true,
                  separator: '\n\n'
              },
              bootstrap: {
                  options: {
                      banner: '&lt;%= bootstrap.banner %&gt;&lt;%= bootstrap.jqueryCheck %&gt;'
                  },
                  src: [
                      '&lt;%= bootstrap.src %&gt;/js/transition.js',
                      // '&lt;%= bootstrap.src %&gt;/js/alert.js',
                      // '&lt;%= bootstrap.src %&gt;/js/button.js',
                      // '&lt;%= bootstrap.src %&gt;/js/carousel.js',
                      '&lt;%= bootstrap.src %&gt;/js/collapse.js',
                      '&lt;%= bootstrap.src %&gt;/js/dropdown.js',
                      // '&lt;%= bootstrap.src %&gt;/js/modal.js',
                      // '&lt;%= bootstrap.src %&gt;/js/tooltip.js',
                      // '&lt;%= bootstrap.src %&gt;/js/popover.js',
                      // '&lt;%= bootstrap.src %&gt;/js/scrollspy.js',
                      // '&lt;%= bootstrap.src %&gt;/js/tab.js',
                      // '&lt;%= bootstrap.src %&gt;/js/affix.js'
                  ],
                  dest: '&lt;%= project.app %&gt;/js/plugins/bootstrap.js'
              },
              plugins: {
                  files: {
                      '&lt;%= project.app %&gt;/js/plugins.js': ['&lt;%= project.app %&gt;/js/plugins/bootstrap.min.js', '&lt;%= project.app %&gt;/js/plugins/*.min.js']
                  }
              }
          },
          uglify: {
              bootstrap: {
                  options: {
                      banner: '&lt;%= bootstrap.banner %&gt;'
                  },
                  files: {
                      '&lt;%= project.app %&gt;/js/plugins/bootstrap.min.js': '&lt;%= concat.bootstrap.dest %&gt;'
                  }
              },
              all: {
                  options: {
                      preserveComments: 'some',
                      report: 'min'
                  },
                  files: [{
                      expand: true,
                      cwd: '&lt;%= project.app %&gt;/js/',
                      src: ['*.js', '!plugins.js'],
                      ext: '.min.js',
                      dest: '&lt;%= project.app %&gt;/js/'
                  }]
              }
          },
          cssmin: {
              options: {
                  report: 'min'
              },
              dist: {
                  expand: true,
                  cwd: '&lt;%= project.app %&gt;/css/',
                  src: ['*.css', '!*.min.css'],
                  dest: '&lt;%= cssmin.dist.cwd %&gt;',
                  ext: '.min.css'
              }
          },
          imagemin: {
              dist: {
                  files: [{
                      expand: true,
                      cwd: '&lt;%= project.app %&gt;/img',
                      src: ['{,*/}*.{gif,jpeg,jpg,png}'],
                      dest: '&lt;%= project.dist %&gt;/img'
                  }]
              }
          }
      });
  
      // Register tasks
      // ==================================================
  
      // Run local server
      grunt.registerTask('serve', function (target) {
          if (target === 'dist') {
              return grunt.task.run(['build', 'connect:dist:keepalive']);
          }
  
          grunt.task.run([
              'connect:livereload',
              'watch'
          ]);
      });
  
      // Build JS
      grunt.registerTask('build-js', [
          'concat:bootstrap',
          'uglify',
          'concat:plugins'
      ]);
  
      // Build CSS
      grunt.registerTask('build-css', [
          'sass:dist',
          'autoprefixer',
          'cssmin'
      ]);
  
      // Minify images
      grunt.registerTask('test', ['imagemin']);
  
      // grunt.registerTask('default', ['']);
  
  };
  </code></pre>
  
  <p>package.json (all dependencies are up to date):</p>
  
  <pre><code>{
    "name": "project",
    "version": "0.0.0",
    "dependencies": {},
    "devDependencies": {
      "load-grunt-tasks": "~0.2.1",
      "time-grunt": "~0.2.6",
      "grunt": "~0.4.2",
      "grunt-contrib-watch": "~0.5.3",
      "grunt-contrib-connect": "~0.6.0",
      "grunt-autoprefixer": "~0.6.3",
      "grunt-contrib-concat": "~0.3.0",
      "grunt-contrib-uglify": "~0.2.7",
      "grunt-contrib-cssmin": "~0.7.0",
      "grunt-sass": "~0.9.0",
      "jpegtran-bin": "~0.2.0",
      "grunt-contrib-imagemin": "~0.4.0"
    }
  }
  </code></pre>
  
  <p>I'm on Windows 7 32-bit, gruntjs v.0.4.2, nodejs v0.10.22. Any ideas what may causes this problem? And how would I fix it? Thanks a lot.</p>