Back to feed
Dev.to
Dev.to
6/25/2026
How TypeScript 5.7's `--module nodenext` Changes Are Breaking Legacy Express Apps (and How to Fix Them)

How TypeScript 5.7's `--module nodenext` Changes Are Breaking Legacy Express Apps (and How to Fix Them)

Short summary

TypeScript 5.7's nodenext module mode now strictly enforces Node.js module resolution rules at compile time, breaking legacy Express apps that mix CommonJS and ESM. Three issues arise: require() calls to ESM-only packages fail, JSON imports need explicit resolveJsonModule configuration, and relative imports must include .js extensions. Fix by enabling resolveJsonModule in tsconfig, adding explicit file extensions to imports, and using dynamic import() for ESM-only dependencies.

  • TypeScript 5.7 tightened nodenext mode to match Node.js behavior, breaking previously tolerated module patterns
  • Three breaking changes: require() on ESM-only packages, missing resolveJsonModule config, and relative imports without .js extensions
  • Fixes include tsconfig updates, explicit file extension migration, and using dynamic import() for forward compatibility

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Explore more