You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The whole way that mssql and msnodesqlv8 work together seems wonky. It's taken a lot of time, but I got it to simply connect with plain javascript and using require. However I am trying to use it in a module (server-size sveltekit, but trying to get it working in node .mjs) and can't figure out how to get it to work without using 'require' which isn't supported. Any help or samples would be appreciated.
// This works in a plain .js file, but throws this error in an .mjs file// *** ReferenceError: require is not defined in ES module scope, you can use import instead ***// const sql = require('mssql/msnodesqlv8')// Trying to change it to an import gives an error:// *** Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\git\t\mssql\node_modules\mssql\msnodesqlv8' imported from C:\git\t\mssql\index.mjs ***import*assqlfrom'mssql/msnodesqlv8'
The text was updated successfully, but these errors were encountered:
I am afraid i do not have any association with this module, so cannot help - does this work?
import{createRequire}from'module'constrequire=createRequire(import.meta.url)constsql=require('mssql/msnodesqlv8')constconnectionString="Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\\node;Database=scratch;Trusted_Connection=yes;"constconfig={connectionString: connectionString}asyncfunctionrunner(){constpool=awaitsql.connect(config)constres=awaitpool.query('select top 3 * from syscolumns')console.log(JSON.stringify(res,null,4))awaitpool.close()}runner().then(()=>{console.log('done')})
The whole way that mssql and msnodesqlv8 work together seems wonky. It's taken a lot of time, but I got it to simply connect with plain javascript and using require. However I am trying to use it in a module (server-size sveltekit, but trying to get it working in node .mjs) and can't figure out how to get it to work without using 'require' which isn't supported. Any help or samples would be appreciated.
The text was updated successfully, but these errors were encountered: