tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.22k stars 464 forks source link

sql Type is undefiend in nestJS #1533

Closed matul1 closed 10 months ago

matul1 commented 11 months ago

ErrorMessage : [Nest] 22012 - 2023. 08. 24. 오후 4:49:24 ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'VarChar')

import sql from 'mssql';
const result = await conn
      .request()
      .input('i_strCustomerid', sql.VarChar(50), customer.customerID)
      .execute('spname');

Expected behaviour:

Actual behaviour:

[Nest] 22012 - 2023. 08. 24. 오후 4:49:24 ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'VarChar')

Configuration:

"dependencies": {
    "@nestjs/common": "^10.0.0",
    "@nestjs/config": "^3.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/swagger": "^7.1.8",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "cross-env": "^7.0.3",
    "mssql": "^9.1.3",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/mssql": "^8.1.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  },

Software versions

dhensby commented 11 months ago

The error is that it thinks sql is not defined. I don't know why it's saying that, what's the compiled JS look like? Have you done any debugging?

matul1 commented 10 months ago

The error is that it thinks sql is not defined. I don't know why it's saying that, what's the compiled JS look like? Have you done any debugging?

I solved it by adding the option below to tsconfig.

"esModuleInterop": true,

thanks.