Search code examples
javascriptnpmyeomanyeoman-generator

TypeError: Cannot read Property 'extend' of undefined , Yeoman Generator


I have installed yeoman generator and it is shown in the package.json file , but I get the above error pointing on the Base.^extend in the following line when i run yo my-generator-name

module.exports = generators.Base.extend

complete file looks so:

'use strict';

var generators = require('yeoman-generator');

module.exports = generators.Base.extend({
    method1: function(){
        this.log('Hello World');
    }
})

any help would be great!


Solution

  • It looks like that the extend method has been deprecated and removed by now. You'll have to use class syntax to extend the generator class.

    v2.0.0

    Breaking changes

    Generator.extend() is replaced in favor of class extends Generator {}

    const Generator = require('yeoman-generator');
    module.exports = class extends Generator {
       /* your code here*/
    }