title: import sql from 'mssql'; console.log(sql); // returns undefined
body: <p>I am trying to create a CRUD in Nest.js with SQL Server. I have installed the following packages:</p>
  <p><code>mssql</code> <a href="https://www.npmjs.com/package/mssql" rel="nofollow noreferrer">https://www.npmjs.com/package/mssql</a></p>
  <p><code>@types/mssql</code> <a href="https://www.npmjs.com/package/@types/mssql" rel="nofollow noreferrer">https://www.npmjs.com/package/@types/mssql</a></p>
  <p>I have created a service <code>database.service.ts</code> in which i have the following code:</p>
  <pre><code>import { Injectable } from '@nestjs/common';
  import sql from 'mssql';
  
  @Injectable()
  export class DatabaseService {
    config = {
      user: 'mssql',
      password: 'password',
      server: 'localhost',
      database: 'atm',
      options: {
        encrypt: true,
        trustServerCertificate: true,
      },
    };
  
    async getPool() {
      console.log('SQL obj', JSON.stringify(sql));
      const pool = await sql.connect(this.config);
      return pool;
    }
  }
  </code></pre>
  <p>In app.controller.ts I have the following:</p>
  <pre><code>import { DatabaseService } from './database/database.service';
  import { Controller, Get } from '@nestjs/common';
  
  @Controller()
  export class AppController {
    constructor(private db: DatabaseService) {}
  
    @Get()
    getHello() {
      this.db.getPool().then((pool) =&gt; {
        pool
          .request()
          .query('SELECT 1')
          .then((res) =&gt; {
            return res;
          });
      });
    }
  }
  </code></pre>
  <p>I then run <code>npm run start</code> and make the following <code>GET</code> request with Postman to port 3000:</p>
  <p><a href="https://i.stack.imgur.com/UYZss.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UYZss.png" alt="enter image description here" /></a></p>
  <p>As you can see I get nothing in response and also my <strong>Nest.js server has crashed.</strong></p>
  <p><a href="https://i.stack.imgur.com/yW4w1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yW4w1.png" alt="enter image description here" /></a></p>
  <p>Complete log:</p>
  <pre><code>&gt; cajero-backend@0.0.1 start C:\Users\carlo\Desktop\cajero\backend\cajero-backend
  &gt; 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.
  </code></pre>
  <p>Something that grabbed my attention is that <code>sql</code> is <strong>undefined</strong> in <code>database.service.ts</code> How can I fix this?  What am I doing wrong?</p>