Skip to content

Type error when using verbatimModuleSyntax: true in consumer project #396

Description

@azerum

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

npx tsc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions