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

exception afer upgrading to v2 #1038

Closed
boneskull opened this issue Sep 23, 2017 · 10 comments
Closed

exception afer upgrading to v2 #1038

boneskull opened this issue Sep 23, 2017 · 10 comments
Labels

Comments

@boneskull
Copy link

I have a custom generator here.

For whatever reason, v2.0.0 of this package is causing the failure below. v1.1.1 does not exhibit this behavior.

It should be noted that the src/ dir is not where my generators live! They are transpiled by babel and put into generators/. Removing src from my files property of package.json has no effect; I still get this error.

My generator is linked to my global Node install. This is Node v8.5, yeoman v2.0.0, macOS.

/Users/boneskull/Documents/projects/generator-bonestorm/src/app/index.js:14
  constructor (args, opts) {
                           ^
TypeError: Class constructor Generator cannot be invoked without 'new'
    at new Bonestorm (/Users/boneskull/Documents/projects/generator-bonestorm/src/app/index.js:14:28)
    at Environment.instantiate (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:403:12)
    at Environment.create (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:381:17)
    at Environment.run (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:438:28)
    at env.lookup (/usr/local/lib/node_modules/yo/lib/cli.js:156:11)
    at Environment.resolver.lookup (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/resolver.js:50:12)
    at init (/usr/local/lib/node_modules/yo/lib/cli.js:117:7)
    at pre (/usr/local/lib/node_modules/yo/lib/cli.js:76:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/yo/lib/cli.js:205:3)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
@SBoudrias
Copy link
Member

Hey, I took a quick look and can't find anything obvious (especially that error is a bit weird).

I wonder if this could have something to do with the babel compilation result?

@boneskull
Copy link
Author

Don’t think so... downgrading to pre-2.0.0 works fine. Can I provide more info?

@boneskull
Copy link
Author

Oh rather that babel is choking on THIS package? hmm....

@HsuTing
Copy link

HsuTing commented Jan 21, 2018

I have same problem when I upgrade to v2.x and use babel.

@HsuTing
Copy link

HsuTing commented Jan 21, 2018

I know why it will throw TypeError. Owing to babel, babel will transform class to function like:

function App(args, options) {
  _classCallCheck(this, App);
  ...
}

This does not use class in node.js, but Generator is a class type in node.js. In the class which is transformed by babel, it will call a parent class as function. However, class in node.js is not a function. This is a real class type. As a result, it will throw a TypeError.

I build a temporary package with babel to support this problem: @hsuting/yeoman-generator .
Hope this will help someone who has the same problem.

@HsuTing
Copy link

HsuTing commented Jan 22, 2018

I ask in babel slack and get the solution.
You can set the .babelrc as this:

{
  presets: [
    ['env', {
      targets: {
        node: true
      }
    }]
  ]
}

This will not transform class to function.
And you can extends the Generator from yeoman-generator@v2.x.

@cjam
Copy link

cjam commented Mar 27, 2018

Ran into this same issue while using typescript (no babel). Downgrading to pre 2.x seems to have fixed it.

@christopher-taormina-zocdoc

I've also run into the same issue, downgrading has helped me as well

@tonyhallett
Copy link
Contributor

For those using typescript change your compiler options to target ES2015

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2020

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Jan 1, 2020
@github-actions github-actions bot closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants