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

TypeError: Class constructor Actor cannot be invoked without 'new' #2742

Closed
nparoski opened this issue Aug 20, 2023 · 7 comments
Closed

TypeError: Class constructor Actor cannot be invoked without 'new' #2742

nparoski opened this issue Aug 20, 2023 · 7 comments
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior stale This issue or PR has not had any activity recently

Comments

@nparoski
Copy link

nparoski commented Aug 20, 2023

Steps to Reproduce

  1. npx create-nx-workspace
  2. nx g @nx/web:application game
  3. Try to extend Actor
  4. Error

Expected Result

I'm expecting this code snippet to work and compile without any errors.

export default class Player extends Actor {
  constructor(actorProps: ActorArgs, game: Engine) {
    super({
      width: 96,
      height: 96,
      color: Color.DarkGray,
      pos: vec(game.halfDrawWidth, game.halfDrawHeight),
      ...actorProps,
    });
  }
}

Actual Result

main.6b38f55fbbef9977.js:223 Uncaught (in promise) TypeError: Class constructor Actor cannot be invoked without 'new'
    at new Player (main.6b38f55fbbef9977.js:223:44187)
    at main.6b38f55fbbef9977.js:223:46937
    at main.6b38f55fbbef9977.js:223:46741
    at Object.next (main.6b38f55fbbef9977.js:223:46857)
    at asyncGeneratorStep (main.6b38f55fbbef9977.js:223:45569)
    at _next (main.6b38f55fbbef9977.js:223:47444)
    at main.6b38f55fbbef9977.js:223:47594
    at new Promise (<anonymous>)
    at main.6b38f55fbbef9977.js:223:47356
    at 149 (main.6b38f55fbbef9977.js:223:47611)

Clicking on error displays this (line 3 is where error is at)

       var Player = function(Actor) {
            function Player(actorProps, game) {
                return Actor.call(this, player_extends({ // <------- this is where error is at.
                    width: 96,
                    height: 96,
                    color: __webpack_exports__Color.DarkGray,
                    pos: __webpack_exports__vec(game.halfDrawWidth, game.halfDrawHeight)
                }, actorProps))
            }
            return !function(subClass, superClass) {
                if ("function" != typeof superClass && null !== superClass)
                    throw TypeError("Super expression must either be null or a function");
                subClass.prototype = Object.create(superClass && superClass.prototype, {
                    constructor: {
                        value: subClass,
                        writable: !0,
                        configurable: !0
                    }
                }),
                superClass && player_set_prototype_of(subClass, superClass)
            }(Player, Actor),
            Player.prototype.onInitialize = function(engine) {
                console.log(engine),
                this.graphics.use(idleAnimation),
                this.graphics.add("run", runAnimation)
            }
            ,
            Player
        }(__webpack_exports__Actor);

Environment

  • tsconfig.json: compilerOptions.target: es2015. i've changed it to es6 but no difference
  • tsconfig:
{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {}
  },
  "exclude": ["node_modules", "tmp"]
}

  • nx: 16.7.2
  • @nx/web 16.7.1
  • browsers and versions: Chrome 115.0.5790.171 (Official Build) (64-bit)
  • operating system: Windows 10
  • Excalibur versions: 0.28
@nparoski
Copy link
Author

Repo link https://github.com/nparoski/web-game

@eonarheim
Copy link
Member

Hi @nparoski thanks for the issue!

I'll look into this, I haven't seen this before!

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Aug 21, 2023
@nparoski
Copy link
Author

@eonarheim there is branch called, feature/es6-classes I belive. (Thought I linked to it but just saw I didnt.)

Also Im not seeing any difference when changing tsconfig compilerOptions.target to es6 in bundles. Might be related to nx and not excalibur at all🤔

Thanks for help and time.

@nparoski
Copy link
Author

Also opened issue on nx/web about it.nrwl/nx#18735

@nparoski
Copy link
Author

@eonarheim Error is resolved and it indeed was problem with nx using swc under the hood. You can checkout nrwl/nx#18735 to see more details

@github-actions
Copy link

This issue hasn't had any recent activity lately and is being marked as stale automatically.

@github-actions github-actions bot added the stale This issue or PR has not had any activity recently label Oct 21, 2023
@eonarheim
Copy link
Member

Closing for now! Let me know if we should update some docs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior stale This issue or PR has not had any activity recently
Projects
None yet
Development

No branches or pull requests

2 participants