Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator.run is not a function #806

Open
Vladyslav317 opened this issue Apr 11, 2024 · 2 comments
Open

generator.run is not a function #806

Vladyslav317 opened this issue Apr 11, 2024 · 2 comments

Comments

@Vladyslav317
Copy link

Vladyslav317 commented Apr 11, 2024

Type of issue

Bug report

My environment

  • OS version/details: macOS 14.4.1
  • Node version: 20.10.0 (run node --version in your terminal)
  • npm version: 10.2.3 (run npm --version in your terminal)
  • Version of yo : 5.0.0 (run yo --version in your terminal)

Expected behavior

Should proceed with generating a project by adding src folder

Current behavior

generator.run is not a function

Steps to reproduce the behavior

yo the name of the generator

Command line output

generator.run is not a function
@szm1002
Copy link

szm1002 commented Jun 18, 2024

+1

@yenoh2
Copy link

yenoh2 commented Jul 1, 2024

I worked through detailed debugging to understand how to write a generator that works with the latest yeoman yo and generator. At this point none of the Yeoman documentation describes how to build a working generator with the latest version. Here's a fully functioning example that uses the latest version of yeoman and the yeoman generator: https://github.com/yenoh2/generator-hac-tf-module

update your package.json adding "type": "module"
Since the newer version uses ESM you need to update your generator use imports instead of 'require' in your index.js file.
Example:
import _ from 'lodash';
import Generator from 'yeoman-generator';
import askName from 'inquirer-npm-name';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// see full example here: https://github.com/yenoh2/generator-hac-tf-module/blob/master/generators/app/index.js
Your export for your extended generator should look like this:
export default class extends Generator {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants