Please install mysql2 package manually

See original GitHub issue

What are you doing?

when I run ‘node app.js’ ,throw error ‘new Error(‘Please install mysql2 package manually’);’ but i’m installed mysql2. my local client haven’t this problem, just my ubuntu 14 server have it.

You must set the NODE_ENV environment variable
/home/www/test/tougao-server/node_modules/_sequelize@4.37.10@sequelize/lib/dialects/mysql/connection-manager.js:38
        throw new Error('Please install mysql2 package manually');
        ^

Error: Please install mysql2 package manually
    at new ConnectionManager (/home/www/test/tougao-server/node_modules/_sequelize@4.37.10@sequelize/lib/dialects/mysql/connection-manager.js:38:15)
    at new MysqlDialect (/home/www/test/tougao-server/node_modules/_sequelize@4.37.10@sequelize/lib/dialects/mysql/index.js:14:30)
    at new Sequelize (/home/www/test/tougao-server/node_modules/_sequelize@4.37.10@sequelize/lib/sequelize.js:239:20)
    at Object.<anonymous> (/home/www/test/tougao-server/controllers/adController.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/www/test/tougao-server/router/ad.js:2:20)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at /home/www/test/tougao-server/router/index.js:37:17
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/www/test/tougao-server/router/index.js:36:4)

What do you expect to happen?

I wanted Foo!

What is actually happening?

But the output was bar!

Output, either JSON or SQL

Dialect: mysql __Database version:_5.5.60 __Sequelize version: 4.37.10 __Tested with latest release: no

Note : Your issue may be ignored OR closed by maintainers if it’s not tested against latest version OR does not follow issue template.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

74reactions
MaximusMcCanncommented, May 17, 2019

@arielrahmane wherever you import sequelize you can set the dialectModule in the options. Example below.

import Sequelize from 'sequelize';
import mysql2 from 'mysql2'; // Needed to fix sequelize issues with WebPack

const sequelize = new Sequelize(
  process.env.DB_NAME,
  process.env.DB_USER,
  process.env.DB_PASSWORD,
  {
    dialect: 'mysql',
    dialectModule: mysql2, // Needed to fix sequelize issues with WebPack
    host: process.env.DB_HOST,
    port: process.env.DB_PORT
  }
)

export async function connectToDatabase() {
  console.log('Trying to connect via sequelize')
  await sequelize.sync()
  await sequelize.authenticate()
  console.log('=> Created a new connection.')

  // Do something 
}

28reactions
catamphetaminecommented, Apr 24, 2019

If you’re bundling with Webpack, my workaround for v5 is:

// Fix "Please install mysql2 package manually".
import mysql2 from 'mysql2';
if (options.dialect === 'mysql') {
  options.dialectModule = mysql2;
}
new Sequelize(options)

The bug is in the code:

  _loadDialectModule(moduleName) {
    try {
      if (this.sequelize.config.dialectModulePath) {
        return require(this.sequelize.config.dialectModulePath);
      }
      if (this.sequelize.config.dialectModule) {
        return this.sequelize.config.dialectModule;
      }
      return require(moduleName);

    } catch (err) {
      if (err.code === 'MODULE_NOT_FOUND') {
        if (this.sequelize.config.dialectModulePath) {
          throw new Error(`Unable to find dialect at ${this.sequelize.config.dialectModulePath}`);
        }
        throw new Error(`Please install ${moduleName} package manually`);
      }

      throw err;
    }
  }

require(moduleName) won’t work with Webpack.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR: Please install mysql2 package manually
i installed mysql2 package globally out of my project folder using : npm install mysql2 -g.
Read more >
Please install mysql2 package manually in NodeJS Application
Introduction. This is an article where the main focus is to solve an error message. The error appear upon executing a NodeJS application....
Read more >
[Solved]-Install mysql2 package manually - error-node.js
For those who have this issue, I solved mine by npm intall -g mysql2 . It happens if you install sequelize-cli globally, it...
Read more >
mysql2 - npm
MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues. npm install --save mysql2....
Read more >
ERROR: Please install mysql2 package manually (15 answers)
ERROR: Please install mysql2 package manuallyFound it helpful? Subscribe to my youtube channel.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found