Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
melleck opened this issue Mar 13, 2024 · 1 comment

Comments

@melleck
Copy link

melleck commented Mar 13, 2024

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants