Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

javascript - Sequelize - Please install mysql2 package manually

I have created a separate helper library to work with databases.

I am then importing this library in my project. When I am trying to create a db connection using mysql dialect, it says the following: Please install mysql2 package manually

I have installed mysql2 library in my root project but it still does not work. Do I have to install mysql2 in the helper library as well ? Is there any way to install a dependency to be visible in other libraries as well ?

I am trying to keep it as small as possible. I want the library to be configurable from the root application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found the solution. Sequelize accepts the dialect option in the constructor. All you need to do is provide it:

const connection = new Sequelize({
    host: 'localhost',
    username: 'root',
    password: 'root',
    database: 'mydb',
    dialect: 'mysql',
    dialectModule: require('mysql2'), <========= IMPORTING DIALECT
    benchmark: true
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...