Wednesday, 21 October 2015

grunt build error : (Error code: EISDIR)


I got this error today:

Warning: Unable to read "dist/public/bower_components/Chart.js" file (Error code: EISDIR). Use --force to continue. Aborted due to warnings.


That because Chart.js use "chart.js" as a folder's name, and my grunt build script think it is a file.....

This is not for Chart.js only,  all libraries which has "xxx.js" as the name, they will have the same issue.

Three solutions for fixing this:

1. change your Gruntfile.js to:

rev: {
      dist: {
        files: {
          src: [
            '<%= yeoman.dist %>/scripts/**/*.js',
            '<%= yeoman.dist %>/styles/**/*.css',
            '<%= yeoman.dist %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= yeoman.dist %>/fonts/**/*.ttf'
          ]
        }
      }
    },
it used to be this: '<%= yeoman.dist %>/public/{,*/}*.js',

However this doesn't work for me.

 

http://stackoverflow.com/questions/18300317/grunt-build-gives-error-code-eisdir-when-trying-to-package-fonts-in-angularjs-a



2. change Gruntfile.js to:

    rev: {
      dist: {
        files: {
          src: [
            '<%= yeoman.dist %>/public/{,*/}*.js',
            '<%= yeoman.dist %>/public/{,*/}*.css',
            '<%= yeoman.dist %>/public/assets/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= yeoman.dist %>/public/assets/fonts/*',
            '!<%= yeoman.dist %>/public/bower_components/Chart.js',
            '!<%= yeoman.dist %>/public/bower_components/angular-chart.js'
          ]
        }
      }
    },


this solution works for me.

This solution is ugly, because you hardcoded the libraries name in you compiling script, and bower.js and package.js are used to decoupling this.

However this is not a big deal, because if these file are exist the build script will process them, if not build script will not crush. so this is still decoupling.

When you use this solution make sure you have the same code in "usemin":

usemin: {
      html: ['<%= yeoman.dist %>/public/{,*/}*.html'],
      css: ['<%= yeoman.dist %>/public/{,*/}*.css'],
      js: ['<%= yeoman.dist %>/public/{,*/}*.js',
            '!<%= yeoman.dist %>/public/bower_components/Chart.js',
            '!<%= yeoman.dist %>/public/bower_components/angular-chart.js'
            ],
      options: {


3. use "filerev" instead of "rev".

first make sure you have  "grunt-filerev": "^0.2.1" in your package.js and run npm install.

here is the script which you should put in your Gruntfile.js to replace rev. (make sure your call "filerev" in "grunt.registerTask('build', [" instead of calling "rev")


    filerev: {
      dist: {
        src: [
          '<%= yeoman.dist %>/scripts/{,*/}*.js',
          '<%= yeoman.dist %>/styles/{,*/}*.css',
          '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
          '<%= yeoman.dist %>/styles/fonts/*'
        ]
      }
    },


However you still need fix issue of "usemin". i will not explain how to do this here. but you can definitely find a better Gruntfile.js works for you.









No comments:

Post a comment