Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Fix: Add backward compatibility for TypeScript 4.3+ and older module resolution#52

Merged
millerm30 merged 2 commits intomasterfrom
Ng6FdIum/3525-polyunity-node-update-help
Jul 10, 2025
Merged

Fix: Add backward compatibility for TypeScript 4.3+ and older module resolution#52
millerm30 merged 2 commits intomasterfrom
Ng6FdIum/3525-polyunity-node-update-help

Conversation

@millerm30
Copy link
Member

Problem:

Customers using TypeScript 4.3.x with "moduleResolution": "node" cannot upgrade from SDK v0.14.0 to v2.5.0 due to module resolution issues. If you could test this that would be great. I have tested this with two configs for typescript and a javascript config and all works. When working with an sdk I will npm run build, npm pack then copy the .tgz file to the test setup and run npm i ./name-of-file-here.tgz

Customer Impact

  • Error: Cannot find module 'notificationapi-node-server-sdk' or its corresponding type declarations
  • Affected: Projects using TypeScript < 4.7 with classic module resolution
  • Workaround: Requires changing moduleResolution to node16/nodenext and restructuring import statements across entire codebase

Trello Ticket:

https://trello.com/c/Ng6FdIum/3525-polyunity-node-update-help

Root Cause

The issue: TypeScript 4.3.x doesn't fully support the "exports" field (support was added in TypeScript 4.7), causing module resolution to fail.

Solution:

Added multi-layered backward compatibility without breaking modern environments:

How It Works:

  • Modern TypeScript (4.7+): Uses exports field with conditional exports
  • Older TypeScript (4.3+): Falls back to main and types fields
  • Intermediate versions: Can use typesVersions mapping

Testing:

Test Scenarios

  • CommonJS require() resolution
  • ESM import resolution
  • TypeScript declaration file access
  • Existing customer upgrade path

Benefits:

  • Zero breaking changes - All existing customers continue to work
  • Seamless upgrades - Customers can upgrade without code changes
  • Future-proof - Maintains optimal experience for modern environments
  • Broad compatibility - Works across TypeScript 4.3+ to latest

Customer Experience:

Before:

// Failed with TS 4.3.x + moduleResolution: "node"
import notificationapi from 'notificationapi-node-server-sdk'; //  Module not found

After:

// Works seamlessly across all supported TypeScript versions
import notificationapi from 'notificationapi-node-server-sdk'; //  Resolves correctly

@GreyNewfie
Copy link
Contributor

GreyNewfie commented Jul 10, 2025

Tested and worked:

  • Node setup using typescript 4.3 with "moduleResolution": "node"
  • Node setup using typescript 5.3 with "moduleResolution": "bundler" and "moduleResolution": "node16"
  • Node setup using commonJS import and ESM import (no typescript)

@millerm30 millerm30 merged commit 416878a into master Jul 10, 2025
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments