Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cssmin is giving me "Path must be a string. Received undefined"

My project is a pretty basic yo/angular project. I have the following cssmin config.

    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>',
        flow: {
          html: {
            steps: {
              js: ['concat', 'uglifyjs'],
              css: ['cssmin']
            },
            post: {}
          }
        }
      }
    },
...
    cssmin: {
      dist: {
        files: {
          '<%= yeoman.dist %>/styles/main.css': [
            '.tmp/styles/{,*/}*.css'
          ]
        }
      }
    },
...
  grunt.registerTask('build', [
    'clean:dist',
    'wiredep',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngAnnotate',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
  ]);

when I run grunt build i get the following error:

Running "cssmin:generated" (cssmin) task
Warning: Path must be a string. Received undefined Use --force to continue.

Aborted due to warnings.


Execution Time (2016-05-26 00:57:04 UTC)
concurrent:dist        15s  
autoprefixer:server   3.3s 
ngAnnotate:dist       3.6s  
cdnify:dist          10.7s  
cssmin:dist          888ms  
Total 34.6s

I have seen this error on other posts, but not with cssmin. I have upgraded my libraries in package.json to the latest, which could be the cause.

This project was building fine at one time. I can't determine what path is missing. Does anyone know what path I'm missing?

like image 541
Pompey Magnus Avatar asked May 26 '16 02:05

Pompey Magnus


3 Answers

Actually that problem is fixed, please update your version for the v1.0.2 link here

like image 169
drmartin Avatar answered Nov 01 '22 20:11

drmartin


The answer referred to in the above replies worked for me.

So in node_modules/grunt-contrib-cssmin/tasks/cssmin.js, on line 41, add an or empty string to the parameter:

//before
options.relativeTo = path.dirname(availableFiles[0]);

//after
options.relativeTo = path.dirname(availableFiles[0] || '');

From: https://github.com/gruntjs/grunt-contrib-cssmin/pull/271/commits/11e655873dfa58b6edcda0113cee612f7a6b2ab9?diff=split

like image 23
Eric Grotke Avatar answered Nov 01 '22 22:11

Eric Grotke


EDIT: Answer is now obsolete, see https://stackoverflow.com/a/39482214/1215723 below

More info running the verbose option:

youri$ grunt -v

Running "cssmin:generated" (cssmin) task
Verifying property cssmin.generated exists in config...OK
Files: [no src] -> dist/styles/vendor.css
Files: .tmp/styles/main.css -> dist/styles/main.css
Options: rebase=false, report="min", sourceMap=false
Warning: Path must be a string. Received undefined Use --force to continue.

Looks like we are not alone. By following the issue breadcrumbs, I found:

  • generator-angular #1218
  • clean-css #774
  • node #5348

The suggested workaround is to downgrade to node v5, and indeed, it works (for me). You can also install a node version manager if you find it more convenient.

like image 5
youri Avatar answered Nov 01 '22 21:11

youri