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

instantiatedGenerator.run is not a function #258

Open
houseBetter opened this issue Nov 26, 2023 · 25 comments
Open

instantiatedGenerator.run is not a function #258

houseBetter opened this issue Nov 26, 2023 · 25 comments

Comments

@houseBetter
Copy link

cann't create an app。

image

node and package version

node v18.17.0
npm 9.6.7
yo 5.0.0
generator-generator 5.1.0

System

OS: macOS 12.6
CPU: (8) arm64 Apple M1

@jedaan

This comment has been minimized.

@ekeel

This comment has been minimized.

@j4k0xb

This comment has been minimized.

@jonathanwork

This comment has been minimized.

@weshouman
Copy link

Workaround
I had to downgrade yo to get it working, for example

npm install -g [email protected] generator-generator

@ruieloi

This comment has been minimized.

@takashi013

This comment has been minimized.

@Aiwwa

This comment has been minimized.

@Vladyslav317

This comment has been minimized.

@AmroKhatib77

This comment has been minimized.

@Aiwwa

This comment has been minimized.

@JosXa

This comment has been minimized.

@NgocLe1001

This comment has been minimized.

@NgocLe1001

This comment has been minimized.

@hcl-z

This comment has been minimized.

@aliridha1510

This comment has been minimized.

@yenoh2
Copy link

yenoh2 commented Jun 28, 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. I'm thinking this project needs to be updated in a similar way. Based on my efforts with my generator, it looks like this project needs to refactored to use import instead of require. Here's a fully functioning generator example that uses the latest version of yeoman and the yeoman generator: https://github.com/yenoh2/generator-hac-tf-module

  1. update your package.json adding "type": "module"
  2. 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
  3. Your export for your extended generator should look like this:
    export default class extends Generator {

@ralphcorrigan

This comment has been minimized.

@LumiereLodi

This comment has been minimized.

@ralphcorrigan

This comment has been minimized.

@soumilbaldota

This comment has been minimized.

@jarogamer56

This comment has been minimized.

@jozefizso

This comment has been minimized.

@ntt77

This comment has been minimized.

@JoshuaKGoldberg
Copy link

👋 Hi all! We're resuming maintenance on Yeoman and picking up old issues like this one. See yeoman/yeoman#1779.

I can reproduce this locally with:

npm i -g yo generator-generator
yo generator
yo generator
? Your generator name generator-yotest
? The name above already exists on npm, choose another? No
Your generator must be inside a folder named generator-yotest
I'll automatically create this folder.
(node:60092) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

Just found a `.yo-rc.json` in a parent directory.
Setting the project root at: /Users/josh/repos/yotest
Error generator 

instantiatedGenerator.run is not a function

Digging through, I'm pretty sure the root cause is that generator-generator depends on a very old version of yeoman-generator:

"yeoman-generator": "^3.1.1",

The variable name instantiatedGenerator no longer exists in the latest versions of yeoman-generator. In the Git history, the instantiatedGenerator.run line hasn't existed for a few years. It was refactored away starting in yeoman/generator#1206: https://github.com/yeoman/generator/pull/1206/files#diff-92bbac9a308cd5fcf9db165841f2d90ce981baddcb2b1e26cfff170929af3bd1L941-R979 and continuing through a bunch of subsequent changes to the file.

I tried updating the yeoman-generator dependency to the latest ^7.4.0 but was hit with the always-lovely:

require() of ES Module /Users/josh/repos/generator-generator/node_modules/yeoman-generator/dist/index.js from /Users/josh/repos/generator-generator/app/index.js not supported.
Instead change the require of /Users/josh/repos/generator-generator/node_modules/yeoman-generator/dist/index.js in /Users/josh/repos/generator-generator/app/index.js to a dynamic import() which is available in all CommonJS modules.

...so using the latest yeoman-generator dependency is blocked on #265.


I can't promise exactly when we'll resolve #265 and unblock this issue, but I'm hoping it'll be Soon ™. In the meantime downgraded npm install -g [email protected] generator-generator does seem to fix this issue. I've hidden other comments in this thread to emphasize that. Cheers! 🎩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests