[SOLVED] Error updating to version 1.38.0 of PlayCanvas NPM

Hello All,
have just updated the npm versión of canvas and I am getting this error in execution.
Something has changed? (I am using typescript playcanvas migrating from 1.37.1 to 1.38.0)

TypeError: Class constructor ScriptType cannot be invoked without 'new’
at new scriptType (playcanvas.mjs:65478)
at ScriptComponent.create (playcanvas.mjs:53254)
at Cameras.createOrbitCamera (cameras.ts:36)

my code:

camera.script.create("orbitCamera", {
                attributes: {
                    inertiaFactor: 0.2, // Override default of 0 (no inertia)
                    focusEntity: lookatEntity,
                    defaultEntity: defaultLookatEntity
                }
            });

thanks in advance :slight_smile:

Looks like you’re now using the newly introduced module build of the engine (playcanvas.mjs) instead of the ES5 build (playcanvas.js). Can you switch to the ES5 version to see if that works OK?

sorry for my unkowledge. How do you switch to the ES5 version?
Modifying the tsconfig.json?
I have:
{
“compilerOptions”: {
“target”: “es5”,
“module”: “es6”,
“outDir”: “./dist/”,

I don’t know actually! Hmm. @kungfooman - do you know?

Well, I have just deleted playcanvas.mjs from the node_modules, and it looks like it fallsback to playcanvas.js. Now it is working :slight_smile:

2 Likes

Hey @slimbuck + @Elliott - we should rebuild the glTF viewer against 1.38.0 and see if it works with the new module.

I am having the same error TypeError: Class constructor ScriptType cannot be invoked without 'new’. For now I’ve changed the package.json of playcanvas in my node_modules folder.

"main": "build/playcanvas.js",
"module": "build/playcanvas.mjs",

to

"main": "build/playcanvas.js",
"module": "build/playcanvas.js",

if you need me to test something, let me know :slight_smile:

1 Like

Hi, I also run into this issue, while I updated my project to the latest PlayCanvas version. Is there any solution in the meantime - did I overlook something? Only thing I did as usual is npm update

In your NPM project, go to node_modules folder, then the playcanvas folder. Open the package.json and change the module one to build/playcanvas.js (described above).

Hi @Ivolutio, thanks for your reply. I read the instructions in this thread, but isn’t it the case as (at least in my case) the node_modules folder is excluded from GIT and when someone else do npm install this error happens again?

Yes, that’s true, so you would have to provide further instructions if other people are involved until this is properly resolved on the module side.

1 Like

That’s what I thought, well I decided for now NOT to update my project until this is fixed on module side.

1 Like

You can also exclude a single library from your package.json from updating by locking its version. Do a stackoverflow search on this, you will find plenty of advice on how to do it.

1 Like

Did you try this yet?
I am still having this same error with 1.39.0. I think it wants me to change the way I am adding script components with ‘new Class’… Is there some documentation for this?

I’ve made an attempt at a fix here:

If you’re brave, feel free to build playcanvas.mjs from that branch and verify it works for you. Otherwise, this will probably be merged and deployed this week as 1.39.1.

1 Like

A fix for this from the amazing @kungfooman has just been merged:

We intend to deploy this as part of the 1.39.1 release before the end of the week. Stay tuned! :smile:

3 Likes

Can confirm, this issue is fixed now, since:

1 Like

Excellent! Thanks for letting us know. :tada:

1 Like