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 EventDispatcher cannot be invoked without 'new' #39

Open
QJvic opened this issue May 10, 2021 · 15 comments
Open

Comments

@QJvic
Copy link

QJvic commented May 10, 2021

TypeError: Class constructor EventDispatcher cannot be invoked without 'new'
with three.js version 0.128.0

@DreamfulWong
Copy link

+1

1 similar comment
@StudioRATATA
Copy link

+1

@Yurbly
Copy link

Yurbly commented May 29, 2021

Same issue. Have a suspicion that it is connected to parcel. Do you use it?

TypeError: Class constructor EventDispatcher cannot be invoked without 'new'
with three.js version 0.128.0

@supjs
Copy link

supjs commented Jun 17, 2021

+1

1 similar comment
@cheneyhuwawadi
Copy link

+1

@Zaniyar
Copy link

Zaniyar commented Jun 23, 2021

same

@peteradamsdev
Copy link

I ran into this issue trying to use three.interaction in Vite.js. My solution was to download the repository and include it directly instead of importing it from node_modules.

Change
import { Interaction } from "three.interaction";
to
import { Interaction } from "../path-to-downloaded-directory/Interaction/src/index.js";

There may be a better way, but this worked for me.

@nartallax
Copy link

This problem is caused by an inconsistency of three.js and three.interaction.js : three.js is distributed with classes declared as class Whatever {} (ES6 way), but distributed version of three.interaction.js is trying to subclass of these classes as superclassConstructor.call(this) (pre-ES6 way).

These two ways of class declaration does not get along well (therefore, an error), so the solution is to match ES versions of distributed code. For that, you may either upgrade distributed version of three.interaction.js (peteradamsdev's solution), or downgrade version of three.js with something like Babell (I failed to do so).

Note that I'm not talking about version of the libraries; I'm talking about what javascript versions libraries' distributions conform to.

Three.js devs claim that official distribution is in ES5, but it's not. Maybe something changed in the last two years.

After all this said, for me the optimal solution was to take the source code of three.interaction.js, use rollup tool to bundle it in single file, then use uglify-js tool to minify the file, then edit file slightly to make it work exactly as distributed (export into THREE and not into separate object); and the resulting file was in ES6.

@michelesalvador
Copy link

@nartallax excellent explanation.
Could you please share here the file you produced?

@nartallax
Copy link

Sure:
three.interaction.js.zip

@AprildreamMI
Copy link

Sure: three.interaction.js.zip

想要在vue中使用这个自定义版本需要这样做

  1. 下载压缩包中的库
  2. 引用库
import * as THREE from 'three'
// 事件点击库
import '@/utils/three.interaction.js'
  1. THREE添加全局变量
const webpack = require('webpack')
// vue.config.js
module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].title = 'vue three'
        return args
      })
      .end()
      .plugin('provide')
      .use(webpack.ProvidePlugin, [{
       // 定义THREE为全局变量
        THREE: 'three'
      }])
      .end()
  }
}
  1. 使用库
const interaction = new THREE.Interaction(renderer, scene, camera)

@sasial-dev
Copy link

sasial-dev commented Dec 18, 2021

Does anyone have a fork of three.interaction on npm that does this?

@b3rz3rkr
Copy link

Have similar issue when trying to use module in browser.
Fixed with copying to my project directory connected to index.js in src directory and changed all paths to "path" + ".js", also fixed paths to three.js module. Not the best solution, but it works.
I think in most cases we got this error after babel or other compiler.

Uncaught (in promise) TypeError: class constructors must be invoked with 'new'
InteractionManager three.interaction.module.js:711
Interaction three.interaction.module.js:4466
three.interaction.module.js:711:12

@juanboschero
Copy link

juanboschero commented Oct 13, 2022

Having the same issue, 'Uncaught TypeError: Class constructor EventDispatcher cannot be invoked without 'new' '.

Using react.js

Please help

@elemermelada
Copy link

Having the same issue, 'Uncaught TypeError: Class constructor EventDispatcher cannot be invoked without 'new' '.

Using react.js

Please help

I speak on behalf of this guy as well. This other guy literally saved our project:

I ran into this issue trying to use three.interaction in Vite.js. My solution was to download the repository and include it directly instead of importing it from node_modules.

Change import { Interaction } from "three.interaction"; to import { Interaction } from "../path-to-downloaded-directory/Interaction/src/index.js";

There may be a better way, but this worked for me.

Thank you so much!

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