javascriptmysqlnpmsequelize.jslru

"Uncaught TypeError: LRU is not a constructor" when trying to connect to a MySQL server via Sequelize


I'm trying to make a web application based on boardgame.io that is just their Tic-Tac-Toe tutorial game, but the results of each match get saved to a MySQL database. In its current state, my code just tries to connect to the database, the result of which should be displayed into the browser's console.

import { Client } from 'boardgame.io/client';
import { TicTacToe } from './Game';

class TicTacToeClient {
  constructor(rootElement) {
    this.client = Client({ game: TicTacToe });
    this.client.start();
    this.rootElement = rootElement;
    this.createBoard();
    this.attachListeners();
    this.client.subscribe(state => this.update(state));
    const { Sequelize, DataTypes } = require("sequelize");
    const sequelize = new Sequelize(
      'tictactoetest',
      'xxxx',
      'xxxx',
       {
         host: 'localhost',
         dialect: 'mysql',
         dialectModule: require('mysql2')
       }
     );
     
     sequelize.authenticate().then(() => 
     {
         console.log('Connection has been established successfully.');
      }).catch((error) => {
         console.error('Unable to connect to the database: ', error);
      });
      const Record = sequelize.define("record", 
      {
          log: 
          {
            type: DataTypes.STRING,
            allowNull: false
          },
          winner: 
          {
            type: DataTypes.STRING,
            allowNull: false
          }
      }, {
          tableName: 'record'
      });
  
      sequelize.sync().then(() => {
          console.log('Record table created successfully!');
       }).catch((error) => {
          console.error('Unable to create table : ', error);
       });
  }

  createBoard() 
  {
    //Irrelevant
  }

  attachListeners() 
  {
    //Irrelevant
  }

  update(state) 
  {
    //Irrelevant
  }
}

const appElement = document.getElementById('app');
const app = new TicTacToeClient(appElement);

The game itself works properly, but instead of the confirmation of success/failure, I get "Uncaught TypeError: LRU is not a constructor". I have tried installing all the LRU libraries I could with NPM, nothing helps. I have successfully ran the same DB connection code in a separate file using "node", so I have no idea where the issue could be.


Solution

  • Alright, I've figured this out "myself". I needed to mess with the versions of in package.json

    "dependencies": {
    "mysql2": "^2.2.5",
    "pg-hstore": "^2.3.4",
    "sequelize": "^5.22.5"
    },
    

    Separating the client and the server also helps.