Skip to content

TypeScript Declaration File Issue with @stomp/stompjs in NestJS + Nx MonorepoΒ #665

@ProgMishaS

Description

@ProgMishaS

Description

When attempting to import types from the @stomp/stompjs package in a NestJS application within an Nx monorepo, TypeScript fails to find declaration files and defaults to any type.

Environment

  • Framework: NestJS
  • Language: TypeScript
  • Build System: Nx (monorepo)
  • Package: @stomp/stompjs
  • Module Resolution: nodenext
  • Target: es2022

Import Usage

import {
  IFrame,
  IMessage,
  Client as StompClient,
  StompConfig,
  StompSubscription,
} from '@stomp/stompjs';

Error Message

Could not find a declaration file for module '@stomp/stompjs'. '/Users/mishabredewold/Documents/Code/trading-powertrader-intraday/node_modules/@stomp/stompjs/bundles/stomp.umd.js' implicitly has an 'any' type.  
Try `npm i --save-dev @types/stomp__stompjs` if it exists or add a new declaration (.d.ts) file containing `declare module '@stomp/stompjs';`

Configuration

tsconfig.base.json

{
  "compilerOptions": {
    "rootDir": ".",
    "composite": true,
    "declarationMap": true,
    "emitDeclarationOnly": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "lib": ["es2022"],
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "esModuleInterop": true,
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "strict": true,
    "useUnknownInCatchVariables": false,
    "target": "es2022",
    "customConditions": ["development"],
    "baseUrl": ".",
    "paths": {
      // paths to local libraries
    }
  },
  "exclude": ["infra/**", "node_modules", "tmp"]
}

app/tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "module": "NodeNext",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "importHelpers": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "noPropertyAccessFromIndexSignature": true
  },
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.lib.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ]
}

Attempted Solutions

  • Verified that @stomp/stompjs is properly installed
  • Checked for existence of @types/stomp__stompjs (not available)
  • Reviewed TypeScript configuration settings

Questions

  • Is this a known compatibility issue with moduleResolution: "nodenext"?
  • Could Nx have any impact on this issue?
  • I have tried resolving this by manually making a module definition but this seemed to not retain Type hinting. Are there any best practices or guidelines I could follow for this?

Additional Context

  • The error specifically points to the UMD bundle (stomp.umd.js) rather than ESM exports, which might be related to the module resolution strategy in use.

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