'Node Mysql Serialize 'ERR_BUFFER_OUT_OF_BOUNDS'

so when i try to run the project i get the above mentioned error. I am simply creating 2 tables and then running serialize.sync(). I am new to both node, mysql, and serielize so i have absolutely no clue why is this happening. Also if you wanna see eveything here is the github project: https://github.com/EmilBabazade/BooksBLog/tree/migrate_to_mysql I also tried deleting blog_books_dev with mysql cli and running again, it gives the same error regardless of wether the database exist or not. Here is what error looks like:

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
server is running on port 3001
tedious deprecated The default value for `config.options.trustServerCertificate` will change from `true` to `false` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. node_modules/sequelize/lib/dialects/mssql/connection-manager.js:63:26
tedious deprecated In the next major version of `tedious`, creating a new `Connection` instance will no longer establish a connection to the server automatically. Please use the new `connect` helper function or call the `.connect` method on the newly created `Connection` object to silence this message. internal/process/task_queues.js:79:11
internal/buffer.js:75
    throw new ERR_BUFFER_OUT_OF_BOUNDS();
    ^

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds
    at boundsError (internal/buffer.js:75:11)
    at Buffer.readUInt8 (internal/buffer.js:243:5)
    at Packet.type (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/packet.js:143:24)
    at IncomingMessageStream.processBufferedData (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/incoming-message-stream.js:72:26)
    at IncomingMessageStream._transform (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/incoming-message-stream.js:107:10)
    at IncomingMessageStream.Transform._read (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at IncomingMessageStream.Transform._write (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83)
    at doWrite (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at IncomingMessageStream.Writable.write (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at Socket.ondata (_stream_readable.js:708:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:273:9)
    at Socket.Readable.push (_stream_readable.js:214:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}
[nodemon] app crashed - waiting for file changes before starting...

Here is the code for database:

const Sequelize = require('sequelize')
const User = require('./models/user')
const Blog = require('./models/blog')
const logger = require('../utils/logger')
const dbConfigs = require('./config')

let sequelize
if (process.env.NODE_ENV === 'production') {
    sequelize = new Sequelize(dbConfigs.production)
} else if (process.env.NODE_ENV === 'development') {
    sequelize = new Sequelize(dbConfigs.development)
} else if (process.env.NODE_ENV === 'test') {
    sequelize = new Sequelize(dbConfigs.test)
} else {
    logger.error('error when connecting to db, invalid or empty NODE_ENV')
    // throw something ..?
}

const userModel = sequelize.define('user', User)
const blogModel = sequelize.define('blog', Blog)
userModel.hasMany(blogModel)
blogModel.belongsTo(userModel)

module.exports = {
    sequelize,
    User: userModel,
    Blog: blogModel,
}

Code for user model:

const Sequelize = require('sequelize')

module.exports = {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    username: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true,
        validate: {
            len: [5, 20],
        },
    },
    name: Sequelize.STRING,
    passwordHash: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    isAdmin: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
    },
}

code for blog model:

const Sequelize = require('sequelize')

module.exports = {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    title: {
        type: Sequelize.STRING,
        AllowNull: false,
        validate: {
            len: [5, 20],
        },
    },
    content: {
        type: Sequelize.STRING,
        AllowNull: false,
        validate: {
            len: [20, 500],
        },
    },
    date: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW,
    },
}

and the options for new Serialize(options) (i deleted password because its my main password for everything irl):

const production = 'link to production db'

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mssql',
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

const test = {
    host: 'localhost',
    database: 'blog_books_test',
    username: 'root',
    password: '',
    dialect: 'mssql',
    port: '3306',
}

module.exports = { production, development, test }


Solution 1:[1]

I wrote mssql instead of mysql:

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mssql',
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

should be:

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mysql', // THIS WAS THE PROBLEM
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

Solution 2:[2]

Same problem. Changed mssql on mysql and it's working.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Emil
Solution 2 ?????? ??????