GitHub Documentation Patreon donate button

Uncaught TypeError: colyseus_js__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor



  • Hi,

    I've started a simple react project using create-react-app and then npm install colyseus.js but when I do:

    import React, { Component } from 'react';
    import Colyseus from 'colyseus.js';
    
    const INITIAL_STATE = {
        myTeamId: null,
        opponentTeamId: null,
        battleState: null,
    };
    
    class BattleScreen extends Component {
        state = INITIAL_STATE;
    
        constructor() {
            super();
    
            this.client = new Colyseus('ws://localhost:2567');
        }
    
        render() {
            return (
                <div></div>
            );
        }
    }
    
    export default BattleScreen;
    

    it yields the following error:

    BattleScreen.js:16 Uncaught TypeError: colyseus_js__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor

    any thoughts?



  • Colyseus.js doesn't have a default export.

    https://docs.colyseus.io/client/client/

    import Colyseus from "colyseus.js";
    // ...
    
    let client = new Colyseus.Client("ws://localhost:2567");
    


  • ah so it should be:

    import { Client } from 'colyseus.js';
    //...
    this.client = new Client('ws://localhost:2567');
    

    otherwise it yields cannot find Client of undefined.

    Thanks, it works now :)


 

GitHub Documentation Patreon donate button

© 2019 Endel Dreyer