responsive-email icon indicating copy to clipboard operation
responsive-email copied to clipboard

TypeScript Declaration Files Not Resolving Properly

Open pgraca97 opened this issue 10 months ago • 1 comments

Package Version: 0.0.4 TypeScript Version: 5.8.3 React Version: 19.1.0 Package Manager: pnpm 10.8.1

Issue Description

TypeScript cannot find declaration files for @responsive-email/react-email when importing components from the package, despite the type definitions existing in the package.

Error Message

Could not find a declaration file for module '@responsive-email/react-email'. 
'/path/to/node_modules/@responsive-email/react-email/dist/index.mjs' implicitly has an 'any' type.
There are types at '/path/to/node_modules/@responsive-email/react-email/dist/index.d.ts', 
but this result could not be resolved when respecting package.json "exports". 
The '@responsive-email/react-email' library may need to update its package.json or typings.

Reproduction Steps

  1. Install the package: pnpm install @responsive-email/react-email
  2. Import components: import { ResponsiveRow, ResponsiveColumn } from "@responsive-email/react-email";
  3. TypeScript reports it cannot find declaration files

I've also tried:

  • Importing from subpaths: import { ResponsiveRow } from "@responsive-email/react-email/responsive-row";
  • Reinstalling the package
  • Clearing the pnpm cache with pnpm store prune

Can you please help me? I want to use the ResponsiveRow and ResponsiveColumn to create a mobile-responsive email with react.email.

pgraca97 avatar Apr 14 '25 16:04 pgraca97

I've managed to work around this issue by adding a declarations.d.ts file in my project with:

declare module '@responsive-email/react-email';

However, this is just hiding the TypeScript error rather than fixing the root cause. Looking at the package.json, it seems the issue might be that the "exports" field needs to include the type definitions. Something like:

"exports": {
  ".": {
    "import": "./dist/index.mjs",
    "require": "./dist/index.js",
    "types": "./dist/index.d.ts"  // This is missing
  },
  "./responsive-row": {
    "import": "./dist/responsive-row.mjs",
    "require": "./dist/responsive-row.js",
    "types": "./dist/responsive-row.d.ts"  // This is missing
  },
  "./responsive-column": {
    "import": "./dist/responsive-column.mjs",
    "require": "./dist/responsive-column.js",
    "types": "./dist/responsive-column.d.ts"  // This is missing
  }
}

I should note that without the declarations.d.ts workaround, the components still function correctly at runtime - the ResponsiveRow and ResponsiveColumn components render properly in my email templates. It's just that TypeScript shows errors during development. This suggests it's purely a TypeScript declaration resolution issue, not a functional problem with the components themselves.

pgraca97 avatar Apr 14 '25 16:04 pgraca97