Azure / azure-kusto-node

JS SDK for the Kusto service
MIT License
53 stars 39 forks source link

Import ES module in CommonJS #332

Open LianwMS opened 6 days ago

LianwMS commented 6 days ago

I am not familiar with the JS/TS code. It should be a common issue. But I cannot find the answer.... I am writing the Azure Function Code in ts. Here is my tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
  }
}

I tried to use azure-kusto-node in my source code:

import { Client, KustoConnectionStringBuilder } from "azure-kusto-data";
const kcsb = KustoConnectionStringBuilder.withSystemManagedIdentity(`https://${clusterName}.kusto.windows.net`);
const client = new Client(kcsb);

The error is

[2024-10-29T08:05:18.558Z] Worker was unable to load entry point "dist/src/functions/***.js": require() of ES Module ***\node_modules\azure-kusto-data\dist-esm\src\index.js from ***\dist\src\functions\****.js not supported.
Instead change the require of index.js in ****\dist\src\functions\****.js to a dynamic import() which is available in all CommonJS modules.

Any suggestion?

AsafMah commented 6 days ago

What version of azure-kusto-node do you use?