'Error: Please install tedious package manually

I'm getting this error when I run my node app that used sequelize library to connect with MSSQL database.

I've tried installing tedious manually both locally and globally but the error is still there.

full stack of the error is below:

Error: Please install tedious package manually
at new ConnectionManager (D:\medibookr-api\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:27:15)
at new MssqlDialect (D:\medibookr-api\node_modules\sequelize\lib\dialects\mssql\index.js:14:30)
at new Sequelize (D:\medibookr-api\node_modules\sequelize\lib\sequelize.js:239:20)
at Object.<anonymous> (D:\medibookr-api\models\index.js:30:17)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (D:\medibookr-api\repositories\users.js:4:16)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (D:\medibookr-api\routes\middleware\authenticated.js:3:25)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)


Solution 1:[1]

To start solving this you have to ensure that you have installed sequelize and tedious and their names appear on your dependencies in the package.json. in the same way if you are using typescript you have to add the @types/node, @types/tedious and @types/validator on your devDependencies.

to do it just run

yarn add sequelize
yarn add tedious
yarn add -D @types/node
yarn add -D @types/tedious
yarn add -D @types/validator

then your package.json should look like this:

"dependencies": {     
  ...
  "sequelize": "^6.6.2",
  "tedious": "^11.0.8"
},
"devDependencies": {
  "@types/node": "^14.6.2",
  "@types/tedious": "^4.0.3",
  "@types/validator": "^13.1.3",

lastly but more important is to import tedious and add it to the sequelize config options as the dialectModule like this:

import { Sequelize } from 'sequelize';
import * as tedious from 'tedious';

...

const config = {
  username: 'user',
  password: 'pass',
  database: 'db',
  host: 'host',
  dialect: 'mssql',
  dialectModule: tedious, //   <----   <---- this is the key!!
  define: { underscored: true },
  dialectOptions,
};

...

const sequelize = new Sequelize(config.database, config.username, config.password, config);

enjoy!! :D

Solution 2:[2]

First:

Check to see if you have tedious or sequelize installed globally using below command.

npm ls -g --depth=0

If you see tedious or sequelize then uninstall them globally using below commands.

npm uninstall -g tedious
npm uninstall -g sequelize

Side note: If you see "sequelize-cli" that is ok to be there globally no need to uninstall that. That is different than "sequelize"

Then:

npm uninstall tedious
npm install tedious

Worked for me :)

Solution 3:[3]

please add this to your packege.json file.

It seems like sequalize makes dynamic require calls to tedious.

"bin": "index.js",
"pkg": {
    "scripts": ["node_modules/tedious/lib/tedious.js", "models/*.js"],
    "assets": ["config/log.json"]
  }

You can find the full explanation here. It worked on my end.

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 Carlos
Solution 2 Patrick Sierak
Solution 3 David Donari