Cannot read property 'FIT' of undefined

Hello,

I was trying to add ‘fit to window’ function, however, the mode: Phaser.Scale.FIT, seems to not work. Here’s the code of my config:

var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scale: {
// Fit to window
mode: Phaser.Scale.FIT,
// Center vertically and horizontally
autoCenter: Phaser.Scale.CENTER_BOTH
},
scene: {
preload: preload,
create: create,
update: update
},
physics: {
default: ‘arcade’,
arcade: {
debug: false,
gravity: {
x: 0,
y: 0
}
}
}
};

I’m getting an error: Uncaught TypeError: Cannot read property ‘FIT’ of undefined in my developer’s console. Searched in an out the stackoverflow without any success.

:wave:

What Phaser version shows in console?

Very early Phaser 3 doesn’t have Phaser.Scale. If so just update it.

How can I update it?
I just pulled the whole repository from GitHub and thought it would be the latest version

Sorry, I know it’s been quite a while but here’s how I solved this issue just in case anyone still needs this. I got the same error but I did have the latest version from GitHub. Turns out I was working on an example from the tutorial which uses an early version. There’s a version num inside the code (something looks like phaser@3.11.0). I changed that number to the latest version, the code worked.

1 Like

Download the “JS” link in https://phaser.io/download/stable, e.g, https://github.com/photonstorm/phaser/releases/download/v3.60.0/phaser.js, or if you use the CDN link, just change the version number, e.g., https://cdn.jsdelivr.net/npm/phaser@3.60.0/dist/phaser.js.

You don’t need the whole repository unless you’re building Phaser yourself.