Skip to content

Cannot use without 'require'? #305

Description

@jasong-au

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 * as sql from 'mssql/msnodesqlv8'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions