The documentation for msnodesqlv8
npm package uses this syntax for typescript.
import { SqlClient } from "msnodesqlv8";
const sql: SqlClient = require("msnodesqlv8");
See: https://github.com/TimelordUK/node-sqlserver-v8#typescript
However this is the only place in my code where I'm using a require
everything else is import
ES style.
This works fine for my Azure function on my local machine. However when I upload to Azure it errors, but doesn't give me any reason in the streaming logs. I am using tsc
to compile.
When I remove the require line, it works ok. I assume the issue is the require statement. I can't figure out the "ES way" of importing msnodesqlv8.
My preference is just to change this to an import - but not sure whether this is possible.
I guess my fallback is using babel - which seems a bit overkill for this situation.
Any ideas? Or do I have to get it working using Babel?
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"strict": false,
},
"include": ["**/*"],
"exclude": ["**/*.test.ts"]
}
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"prestart": "npm run build",
"start": "func start",
"test": "jest",
"prepare": "husky install"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@jest/globals": "^29.3.1",
"@types/babel__core": "^7.1.20",
"@types/jest": "^29.2.4",
"@types/node": "16.x",
"babel-jest": "^29.3.1",
"husky": "^8.0.2",
"jest": "^29.3.1",
"ts-jest": "^29.0.3",
"typescript": "^4.0.0"
},
"dependencies": {
"@azure/functions": "^3.5.0",
"@ringcentral/sdk": "^4.7.3",
"date-fns": "^2.29.3",
"msnodesqlv8": "^3.0.1"
}
}