I edited my question beacuse I still have the same problem.
I'm using webpack, TypeScript and Sequelize. I'm trying to use Sequelize in a backend TypeScript file.
I installed Sequelize and Sequelize TypeScript by npm.
npm i sequelize
npm i sequelize-typescript
Then, in my server.ts file, I test the connection like this:
import {Sequelize} from 'sequelize-typescript';
const sequelize = new Sequelize({
database: 'dbgala',
dialect: 'mysql',
username: 'root',
password: ''
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
When I build my app, I have an error in my node console: "module mysql not found".
So I did npm i mysql
And now, I have lots of errors in my console:
This is my webpack config :
module.exports = {
entry: "./server/server.ts", // server.ts is the backend
output: {
filename: "bundle.js",
path: __dirname + "/dist"
},
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
'awesome-typescript-loader'.
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
builds.
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
};
I'm trying these solutions https://github.com/sequelize/sequelize/issues/7509 and https://github.com/sequelize/sequelize/issues/7509#issuecomment-335312273
I don't understand what is the problem. Does anyone have an idea? Thank you.
