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

4

8

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?

Phytogenesis answered 26/5, 2016 at 2:16 Comment(2)
I found this: github.com/yeoman/generator-angular/issues/1320, try using NVM to switch to Node 0.10.45.Flittermouse
The thread that @Flittermouse linked to contains another link by peterkwidjaja with a solution that is a patch to cssmin that doesn't require a downgrade of node github.Blasto
M
8

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

Melaniamelanic answered 14/9, 2016 at 3:49 Comment(0)
B
7

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

Bandicoot answered 7/7, 2016 at 1:9 Comment(0)
A
5

EDIT: Answer is now obsolete, see https://mcmap.net/q/1246999/-cssmin-is-giving-me-quot-path-must-be-a-string-received-undefined-quot 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:

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.

Arcboutant answered 31/5, 2016 at 16:20 Comment(3)
download do node v5? am i alone in frustration about grunt?Hollah
You are not alone.Leonhard
absolete, see comment from drmartinHypervitaminosis
G
5

You just need to:

change with this in your package.json

"grunt-contrib-cssmin": "^1.0.2",

then

npm install
Gongorism answered 4/12, 2016 at 18:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.