THREE.RenderTarge is not a constructor

When I use

collisionPosRT = new THREE.RenderTarget(1024, 1024);

There throw an error “THREE.RenderTarge is not a constructor”,my three version is latest,Why?Who can help me?Thanks!

Maybe you are using an outdated version of three.js? Try it with the latest one.

Try this:
collisionPosRT = new THREE.WebGLRenderTarget(1024, 1024);

it’s indeed WebGLRenderTarget. i wonder … do you have types installed? your IDE should have marked that code with a red squiggly line, telling you this class doesn’t exist. you would install types no matter if you use typescript or not, the IDE will take it and now you have auto complete, error checks and on-hover info.

npm install @types/three --dev

The RenderTarget class is used with webgpu in this example.

If I have not seen it wrong, it has existed since r155.

If you copied and pasted the error message, you misspelled the name of the class.

there show “THREE.RenderTarget” is a constructor :rofl:

Yes, This is the part of the code I’m using, and my threejs version is r158,and
there show “THREE.RenderTarget” is a constructor :joy:

this is Error Info

Please provide a live example that demonstrates the runtime error. You can use the following template for this: three.js dev template - module - JSFiddle - Code Playground

didn’t know it existed, so this is a webgpu thing? either way, i tried and it worked.

import * as THREE from 'three'

const rt = new THREE.RenderTarget()

so it has to be something with your build system. the warning you get “multiple instances of three.js being imported” doesn’t sound good either, it’s potentially a mixup. where do you get “THREE.” from anyway? do you import it like in the snippet above?

1 Like

We try to generalize some components so they make sense it context of WebGL and WebGPU. The engine can derive specialized classes when distinct code paths are required. E.g. there is the Backend class and then WebGLBackend and WebGPUBackend.