An unexpected error occurred while attempting to establish a connection to a MySQL server using Sequelize: 'LRU is not a constructor'

I have been working on a web application that utilizes boardgame.io's Tic-Tac-Toe tutorial game, with a twist - the results of each match are saved to a MySQL database. The current state of my code involves trying to establish a connection to the database, with the expected outcome being displayed in 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);

Despite the game functioning as intended, I'm encountering an error message

"Uncaught TypeError: LRU is not a constructor"
instead of the expected success/failure confirmation. I've attempted to install various LRU libraries using NPM, to no avail. Interestingly, the same code for establishing DB connection works flawlessly in a separate file using "node". It's puzzling where the problem lies.

Answer №1

If you run a command like npm ls lru-cache, chances are high that one of your direct or indirect dependencies relies on version 8 or an earlier version of lru-cache, but instead, you're receiving version 9 or even 10.

Furthermore, it's highly likely that you're utilizing yarn in this scenario. However, yarn seems to be encountering some issues. I suggest switching to npm or pnpm as they have the capability to properly resolve package dependencies based on the specified version ranges.

Answer №2

After some troubleshooting, I managed to resolve the issue on my own. It turns out that I needed to make modifications to the versions specified in the package.json file.

"dependencies": {
"axios": "^0.21.1",
"express": "^4.17.1",
"react": "^17.0.1"
},

Additionally, separating the client-side and server-side components proved to be beneficial in addressing the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to reduce the width of the dig when it reaches 400

I have a square element with a click event that increases its size by 50 pixels on each click. However, once it reaches a size of 400 pixels, the size decreases by 50 pixels with every click instead. Additionally, when the size of the square reaches 100 p ...

Retrieve a CSV file from the server using Angular and JavaScript

How can a visitor download a CSV file from the server using Angular 7? Many websites suggest creating a CSV file dynamically from data and then using blob creation for downloading. However, I already have the CSV file on the server and want to directly do ...

Mapbox is capable of managing several GEOJSON files by utilizing the loadURL function

I am in the process of creating a map that is designed to load multiple layers from various sources based on a configuration file called config.json. Each layer should trigger a popup when clicked, but oddly enough, I am only able to see the popup for the ...

Troubleshooting a Simple JavaScript Game: Mastermind Edition

Currently, I am working on a JavaScript version of the well-known board game "Mastermind". I have been facing some fundamental issues, mainly with JavaScript arrays and how to reference their values or elements. Despite spending quite a bit of time trying ...

Adding a background image in javascript using data from a MySQL database

My current tech stack includes CodeIgniter, vanilla JavaScript, AJAX, CSS, and MySQL. I am trying to figure out how to set the background of an image that is stored in a MySQL database. While the following code is error-free and working perfectly, my cha ...

Enhance the function for handling AJAX responses

Utilizing this code allows for the handling of responses from an RSS feed. The code efficiently organizes and appends content, separating any embedded videos. While seeking feedback primarily on performance/efficiency, I am also open to other suggestions. ...

What is the correct way to use Deviceready in an Ionic application?

I am currently working on a mobile application built with Cordova and Ionic. The default page of the application requires the use of the SQLLite plugin. https://github.com/brodysoft/Cordova-SQLitePlugin The issue I am facing is that the view contains n ...

Remove all instances of an empty array within a larger array

Is there a way to eliminate an empty array from within a parent array prior to adding a new element? In the structure provided, it appears as follows: var parentArray = [ ['123', '345'], [], ['12'] ] The goal is to remove t ...

I wish to adjust the font size as well as resize the table elements simultaneously

Adjusting the height and width of the table should automatically adjust the font size as well. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Resizable - Default functiona ...

When I attempt to run JavaScript code on the server, it fails to execute properly

When I run my code on my PC without putting it on the server, it works perfectly fine. However, when I upload it to the server and try to call it, I encounter the following error: Uncaught ReferenceError: crearLienzo is not defined at onload ((index): ...

Using jQuery to verify the existence of a lengthy object

Is it possible to achieve this functionality using jQuery or other libraries? Dojo has this feature, but what about the others? $.ifObject(foo.bar.baz.qux[0]) if (foo && foo.bar && foo.bar.baz && foo.bar.baz.qux[0]) With an unkno ...

Choosing rows with matching values in one column and differing values in another column

I have a table with 3 columns: mid, campaign name, and status. I am looking to select a mid that has a specified campaign name and different statuses for that same mid. For example, the desired output should look like this - mid campaign_name status ...

I am struggling to retrieve a value from the angular.forEach function, the flag value is not being obtained. What could be

I'm having an issue with my controller.js file. I can't seem to access the value from the angular.forEach function, specifically the flagvalue isn't being retrieved. Is it because the scope of flagvalue ends when the forEach function complet ...

Count the base in MySQL based on the $_SESSION['username']

I am seeking a solution to determine how many times the same username appears in 2 or more tables. The username I need to search for will be selected from $_SESSION['username'] First Table | id | username | date | | 1 | Mart |28-5-13| | 2 ...

Utilize dynamic function calls in JavaScript

I am trying to dynamically call a function from a string like "User.find". The goal is to call the find() function in the User object if it exists. This is what my attempt looks like: var User = {}; User.find = function(){ return 1; } var input ...

Issue with Material UI select component not displaying the label text

I've been struggling with Material UI's "Select" for quite some time now - spent about 10 hours trying to make it work the way I want. Any help would be greatly appreciated. This question is connected to a previous one: Select MenuItem doesn' ...

The map function is not functioning properly following a state update in React

Hey there! I've come across a bit of a dilemma with my map function that I'm using to map a data array within one of the states in my application. Everything seems to be running smoothly upon the initial load, but as soon as I start adding new d ...

Returning to the previous state in AngularJS when unchecking a checkbox

I'm a beginner when it comes to using angularjs HTML File: <div class='col-md-2 searchdisplay-col1' ng-controller="amenitiesController" style="margin-top:20px"> <h4>Amenities</h4> <label ng-repeat="facilityName ...

Showing changes in state in real-time using ReactJS: A quick guide

Hello, I am currently facing an issue while trying to add a comment and display it immediately on the DOM. Whenever I type any word in the form box, it does not appear in the box. Additionally, pressing the enter key does not trigger a POST request. Could ...

Implementing setDoc with Firebase-Admin using Typescript in Firestore

I'm having issues with my code in config/firebase.ts: import { initializeApp, cert } from 'firebase-admin/app'; import { getFirestore } from 'firebase-admin/firestore' const firebaseAdminApp = initializeApp({ credential: cert( ...