How to Solve Error Message Error: Please install mysql2 package manually in NodeJS Application

Posted on

Introduction

This is an article where the main focus is to solve an error message. The error appear upon executing a NodeJS application. It is executing a file with the name of ‘db-connect-sequelize.js’ using a nodemon tool. The following is the complete output of the error :

[nodemon] app crashed - waiting for file changes before starting...
,[nodemon] restarting due to changes...
[nodemon] starting `node db-connect-sequelize.js`
/home/admin/nodejs/db/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:81
        throw new Error(`Please install ${moduleName} package manually`);
        ^

Error: Please install mysql2 package manually
    at ConnectionManager._loadDialectModule (/home/admin/nodejs/db/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:81:15)
    at new ConnectionManager (/home/admin/nodejs/db/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:25:21)
    at new MysqlDialect (/home/admin/nodejs/db/node_modules/sequelize/lib/dialects/mysql/index.js:15:30)
    at new Sequelize (/home/admin/nodejs/db/node_modules/sequelize/lib/sequelize.js:340:20)
    at Object. (/home/admin/nodejs/db/db-connect-sequelize.js:4:12)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
[nodemon] app crashed - waiting for file changes before starting...

The application is just a simple application. The error appear when a certain line of code is added. The following is the actual line of code where it finally trigger the error :

const db = new sequelize("","","",{
        host: "10.0.2.2",
        dialect: "mysql"
});

The solution to solve the error message is simple. Just install the module for solving the problem. There is a line informing that solution for solving the problem in the above error message output. The following is pointing out that line :

Error: Please install mysql2 package manually

So, just install ‘mysql2’ module. In order to do so, there is an article with the title of ‘How to Install mysql2 Module in NodeJS Application’ in in this link as a reference. The following is the actual execution of the mysql2 module installation :

[admin@10 db]$ npm i mysql2

added 12 packages, and audited 208 packages in 4s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[admin@10 db]$

Since the execution is using a nodemon tool, after the ‘mysql2’ module exist from the installation process, the following output appear :

[nodemon] restarting due to changes...
[nodemon] starting `node db-connect-sequelize.js`
Testing !
Listening on port 3001
Executing (default): SELECT 1+1 AS result
Connected to the database !

As in the above output command execution, the process for solving the problem is finish.

Leave a Reply