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 melleck opened this issue 1 year ago • 3 comments

I have installed msnodesqlv8 but when I am trying to run the following script I am getting the error "Cannot find module 'msnodesqlv8/types' or its corresponding type declarations." on the first import line against 'msnodesqlv8/types'. Please help as this is something urgent I am using node version v21.4.0

import { SqlClient } from 'msnodesqlv8/types'

const sql: SqlClient = require('msnodesqlv8')

const connectionString = 'server=.;Database=Master;Trusted_Connection=Yes;Driver={SQL Server Native Client 11.0}' const query = 'SELECT name FROM sys.databases'

sql.query(connectionString, query, (err, rows) => { if (err != null) { console.error(err) } else { console.log(rows) } })

melleck avatar Mar 13 '24 16:03 melleck

sorry did not respond earlier

with latest version 4.2.1

can you try something like this - or it should work if you add @tsignore above the /types import

import sql from 'msnodesqlv8'
import Connection = MsNodeSqlV8.Connection
import ConnectionPromises = MsNodeSqlV8.ConnectionPromises
async function t() {
    const connectString = 'Driver={ODBC Driver 18 for SQL Server}; Server=DESKTOP-VIUCH90;UID=linux; PWD=linux; Database=node;Encrypt=no'
    const con:Connection = await sql.promises.open(connectString)
    const promises:ConnectionPromises  = con.promises
    const res = await promises.query('select @@servername as server')
    console.log(JSON.stringify(res, null, 4))
    await con.promises.close()
}

t().then(() => {
    console.log('closed')
})

TimelordUK avatar Apr 23 '24 21:04 TimelordUK