Overview
When users use:
- ESM (package.json with `"type": "module")
verbatimModuleSyntax: true in tsconfig.json
Importing @azure/functions (4.9.0) causes failing type checks, even with skipLibCheck: true.
To reproduce
For quick repo, clone and follow README.md of https://github.com/azerum/azure-functions-type-check-bug
I include files here for completeness:
package.json:
{
"type": "module",
"dependencies": {
"@azure/functions": "4.9.0"
},
"devDependencies": {
"typescript": "5.9.3"
}
}
tsconfig.json:
{
"compilerOptions": {
"module": "node16",
"moduleResolution": "node16",
"verbatimModuleSyntax": true,
"esModuleInterop": true,
// Note: does not help
"skipLibCheck": true,
},
"include": ["./src/**/*.ts"]
}
src/index.ts:
import {} from "@azure/functions"
Running
should succeed, but instead produces errors:
node_modules/@azure/functions/src/utils/toolProperties.ts:10:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
10 export class ToolPropertyBuilder implements McpToolProperty {
~~~~~~
node_modules/@azure/functions/src/utils/toolProperties.ts:162:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
162 export const arg = {
~~~~~~
node_modules/@azure/functions/src/utils/toolProperties.ts:225:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
225 export function convertToolProperties(args: Args): McpToolProperty[] {
~~~~~~
node_modules/@azure/functions/src/utils/toolProperties.ts:238:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
238 export function isToolProperties(properties: unknown): properties is Args {
~~~~~~
node_modules/@azure/functions/src/utils/toolProperties.ts:275:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
275 export function normalizeToolProperties(
~~~~~~
Found 5 errors in the same file, starting at: node_modules/@azure/functions/src/utils/toolProperties.ts:10
Reason
index.d.ts of this library imports a .ts (not .d.ts) file on this line. This causes src/utils/toolProperties to be included for compilation in user's project. Compilation fails since:
@azure/functions is published as CJS
src/utils/toolProperties uses ESM syntax - export
verbatimModuleSyntax requires using CJS syntax in CJS files, so it rightfully gives error here
I think library .ts files should not be included in user projects at all, i.e. .d.ts must never import from .ts.
Overview
When users use:
verbatimModuleSyntax: trueintsconfig.jsonImporting
@azure/functions(4.9.0) causes failing type checks, even withskipLibCheck: true.To reproduce
For quick repo, clone and follow README.md of https://github.com/azerum/azure-functions-type-check-bug
I include files here for completeness:
package.json:
tsconfig.json:
src/index.ts:
Running
should succeed, but instead produces errors:
Reason
index.d.ts of this library imports a
.ts(not.d.ts) file on this line. This causessrc/utils/toolPropertiesto be included for compilation in user's project. Compilation fails since:@azure/functionsis published as CJSsrc/utils/toolPropertiesuses ESM syntax -exportverbatimModuleSyntaxrequires using CJS syntax in CJS files, so it rightfully gives error hereI think library
.tsfiles should not be included in user projects at all, i.e..d.tsmust never import from.ts.