Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

common errors

Stéphane Bachelier edited this page Mar 11, 2015 · 1 revision

Common errors

Issue while processing a template

Description

Probably the most annoying issue for any grunt user. It's not an easy issue to fix but has nothing to do with grunt-usemin, it's a javascript error.

You are using template strings in your configuration, which means that you have used this kind of string <%= foo %>.

What grunt tells you is that it failed to process a template, found in your configuration. The not-so-cryptic-but-hard-to-understand warning message is:

Warning: An error occurred while processing a template ([error message]). Use --force to continue.

grunt.template.process delegates to _.template to replaces the template string with your data and something bad happens. The important part is the [error message] part which is the javascript error. You might see (Cannot read property 'options' of undefined), which means that your template is something like <%= variable.options %> where variable is undefined.

How to fix this issue

  • typo: check that there is no typo in your template string. Using <%= pkg.verion %> instead of <%= pkg.version %>.
  • unknow value: when using <%= pkg.version %> in your configuration have you added an key pkg in your grunt configuration which should be an object with a property version.
    grunt.init({
    
       // ...
    
       pkg: {
           version: '1.2.3'
       },
    
       // or better
       pkg: grunt.file.readJSON('package.json'),
       
       // ...
    });
  • option value only defined at runtime: probably the most tricky issue. You might think that grunt will parse your configuration and set the option value at runtime while it might not be the case. It depends on your configuration and the tasks used. You might be able to use a function for a task option, if supported, to fix the value undefined at runtime.
Clone this wiki locally