TimelordUK / node-sqlserver-v8

branched from node-sqlserver, SQL server driver compatible with all versions of Node
Other
135 stars 43 forks source link

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

Open melleck opened 4 months ago

melleck commented 4 months ago

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) } })

TimelordUK commented 3 months ago

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')
})