Open QJvic opened 3 years ago
+1
+1
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
+1
+1
same
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.
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.
@nartallax excellent explanation. Could you please share here the file you produced?
Sure: three.interaction.js.zip
Sure: three.interaction.js.zip
想要在vue中使用这个自定义版本需要这样做
import * as THREE from 'three'
// 事件点击库
import '@/utils/three.interaction.js'
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()
}
}
const interaction = new THREE.Interaction(renderer, scene, camera)
Does anyone have a fork of three.interaction on npm that does this?
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
Having the same issue, 'Uncaught TypeError: Class constructor EventDispatcher cannot be invoked without 'new' '.
Using react.js
Please help
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";
toimport { 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!
TypeError: Class constructor EventDispatcher cannot be invoked without 'new' with three.js version 0.128.0