I am trying to create a CRUD in Nest.js with SQL Server. I have installed the following packages:
As you can see I get nothing in response and also my Nest.js server has crashed.
Complete log:
> cajero-backend@0.0.1 start C:\Users\carlo\Desktop\cajero\backend\cajero-backend
> nest start
[Nest] 11944 - 09/10/2021 16:11:32 LOG [NestFactory] Starting Nest application...
[Nest] 11944 - 09/10/2021 16:11:32 LOG [InstanceLoader] AppModule dependencies initialized 29ms
[Nest] 11944 - 09/10/2021 16:11:32 LOG [RoutesResolver] AppController {/}: 7ms
[Nest] 11944 - 09/10/2021 16:11:32 LOG [RouterExplorer] Mapped {/, GET} route 2ms
[Nest] 11944 - 09/10/2021 16:11:32 LOG [NestApplication] Nest application successfully started 1ms
SQL obj undefined
(node:11944) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'connect' of undefined
at DatabaseService.getPool (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\src\database\database.service.ts:19:28)
at AppController.getHello (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\src\app.controller.ts:15:13)
at C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\@nestjs\core\router\router-execution-context.js:38:29
at InterceptorsConsumer.intercept (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\@nestjs\core\interceptors\interceptors-consumer.js:11:20)
at C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\@nestjs\core\router\router-execution-context.js:46:60
at C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\@nestjs\core\router\router-proxy.js:9:23
at Layer.handle [as handle_request] (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\carlo\Desktop\cajero\backend\cajero-backend\node_modules\express\lib\router\layer.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:11944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Something that grabbed my attention is that sql
is undefined in database.service.ts
How can I fix this? What am I doing wrong?
CodePudding user response:
try import * as sql from 'mssql';
CodePudding user response:
I just fixed it!
I added "esModuleInterop": true,
in tsconfig.json and the problem was solved. Don't know why tho. Can someone please explain? :)