node-sqlserver-v8 icon indicating copy to clipboard operation
node-sqlserver-v8 copied to clipboard

Cannot find module 'msnodesqlv8/types' or its corresponding type declarations.

Open ahjulstad opened this issue 9 months ago • 2 comments

I am developing small Express server in Typescript. I am unable to get type declarations to work, specifically this line:

import { PoolStatusRecord, PoolOptions,  Pool } from "msnodesqlv8/types

gives error message:

TSError: ⨯ Unable to compile TypeScript:
src/index.ts:3:54 - error TS2307: Cannot find module 'msnodesqlv8/types' or its corresponding type declarations.

3 import { PoolStatusRecord, PoolOptions,  Pool } from "msnodesqlv8/types"

I can const sql = require("msnodesqlv8"); and query like this:

app.get("/api/xxx", async (req: Request, res: Response) => {
  res.setHeader("Content-Type", "application/json");

  try {
    sql.query(conn_str, querystr, (err: any, result: any) => {
      // Send the query result as the response
      console.log("Received");
      if (err) {
        console.error("Error executing SQL query:", err);
        res.status(500).send("Internal Server Error");
      } else {
        const jsonData = JSON.stringify(result);
        res.send(jsonData);
      }
    });
  } catch (error) {
    console.error("Error executing SQL query:", error);
    res.status(500).send("Internal Server Error");
  }
});

but I wanted to get the pool to work. (maybe that is not necessary)

package.json :

{
  "name": "bsservermock",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@types/cors": "^2.8.17",
    "@types/express": "^4.17.21",
    "@types/mssql": "^9.1.5",
    "@types/node": "^20.12.10",
    "cors": "^2.8.5",
    "dotenv": "^16.4.5",
    "express": "^4.19.2",
    "msnodesqlv8": "^4.2.1",
    "mssql": "^10.0.2",
    "nodemon": "^3.1.0",
    "tedious": "^18.2.0",
    "ts-node-dev": "^2.0.0"
  },
  "scripts": {
    "build": "npx tsc",
    "start": "node dist/index.js",
    "dev": "nodemon src/index.ts"
  },
  "devDependencies": {
    "typescript": "^5.4.5"
  }
}
node --version
v20.11.1

ahjulstad avatar May 07 '24 11:05 ahjulstad