[SOLVED] FB Instant Games wont plug in

I am using phaser-generator-plus to create my development environment, but I cannot, according to the instructions, add the facebook instant games SDK. In the HTML I added

script src=“https://connect.facebook.net/en_US/fbinstant.6.2.js”></script (syntax intentionally omitted for display)

To the head. I’ve also tried adding it to the body above the comment where scripts are injected.

I also added

new webpack.DefinePlugin({
// Required by Phaser: Enable Canvas and WebGL renderers.
‘CANVAS_RENDERER’: JSON.stringify(true),
‘WEBGL_RENDERER’: JSON.stringify(true),
‘PLUGIN_FBINSTANT’: JSON.stringify(true)
}),

To the gulpfile.js/webpack/config/plugins.js file. But when I launch the game with

export function boot() {
FBInstant.initializeAsync().then(function() {
FBInstant.setLoadingProgress(100);
FBInstant.startGameAsync().then(function() {
return new Phaser.Game(config);
});
});
}

boot();

in the index.js entry file, I get the error FBInstant is not defined. I’ve used other development environments that worked without issue, but for some reason, the phaser-generator-plus setup can’t recognize this plugin. phaser-generator-plus is an extensive and complete environment setup and I would love to continue using it for phaser development. I just can’t get past this wall.

I also tried

export function boot() {
return new Phaser.Game(config);
}
FBInstant.initializeAsync().then(function() {
FBInstant.setLoadingProgress(100);
FBInstant.startGameAsync().then(function() {
boot();
});
});

I just keep getting

17:1 error ‘FBInstant’ is not defined no-undef
18:3 error ‘FBInstant’ is not defined no-undef
19:3 error ‘FBInstant’ is not defined no-undef

:heavy_multiplication_x: 3 problems (3 errors, 0 warnings)

Try to console.log(window.FBInstant) to see if the FBInstant is initialized.

If you can see that, maybe you can change the FBInstant for window.FBInstant.

That did it!

FBInstant {getLocale: ƒ, getPlatform: ƒ, getSDKVersion: ƒ, initializeAsync: ƒ, _populatePlatform: ƒ, …}

Thank you so much. I really need to understand Webpack better. I should have known this. All the other examples referenced FBInstant directly and that threw me as well.

1 Like