当我运行使用sequelize库与MSSQL数据库连接的节点应用程序时,出现此错误。
我尝试在本地和全局手动安装繁琐的操作,但错误仍然存在。
错误的完整堆栈如下:
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)
答案 0 :(得分:0)
请将其添加到您的 packege.json 文件中。
似乎sequalize使动态需要调用乏味。
"bin": "index.js",
"pkg": {
"scripts": ["node_modules/tedious/lib/tedious.js", "models/*.js"],
"assets": ["config/log.json"]
}
您可以找到完整的说明here。它对我有效。
答案 1 :(得分:0)
要开始解决此问题,您必须确保已安装 sequelize 和 tedious,并且它们的名称出现在 package.json
中的依赖项中。同样,如果您使用打字稿,则必须在 devDependencies 中添加 @types/node
、@types/tedious
和 @types/validator
。
只需运行即可
yarn add sequelize
yarn add tedious
yarn add -D @types/node
yarn add -D @types/tedious
yarn add -D @types/validator
那么您的 package.json
应如下所示:
"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",
最后但更重要的是导入 tedious 并将其添加到 sequelize 配置选项作为 dialectModule 像这样:
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);
享受!! :D