惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
C
Cyber Attacks, Cyber Crime and Cyber Security
爱范儿
爱范儿
M
MIT News - Artificial intelligence
V
Vulnerabilities – Threatpost
F
Fortinet All Blogs
月光博客
月光博客
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tor Project blog
T
Troy Hunt's Blog
Latest news
Latest news
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
N
News and Events Feed by Topic
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CERT Recently Published Vulnerability Notes
H
Hacker News: Front Page
C
Cisco Blogs
I
Intezer
P
Privacy International News Feed
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Last Week in AI
Last Week in AI
Scott Helme
Scott Helme
B
Blog
博客园_首页
MyScale Blog
MyScale Blog
Cloudbric
Cloudbric

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
How TypeScript 5.7's `--module nodenext` Changes Are Breaking Legacy Express Apps (and How to Fix Them)
jsmanifest · 2026-06-26 · via DEV Community

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

Most Express app TypeScript failures after upgrading to 5.7 stem from three enforcement changes in --module nodenext that break previously tolerated patterns. Teams discover this when builds that passed in 5.6 suddenly throw module resolution errors with no obvious code changes.

The breaking point arrived when TypeScript 5.7 tightened nodenext mode to match Node.js's actual ESM/CommonJS behavior. Apps that mixed module systems or imported JSON without explicit configuration now fail at compile time. This distinction is critical: the errors surface before runtime, but only after you upgrade.

Understanding the --module nodenext Mode and What Changed in 5.7

TypeScript's nodenext module mode tells the compiler to follow Node.js's native module resolution rules exactly. Before 5.7, the compiler permitted several patterns that Node.js would reject at runtime. The 5.7 release closed those gaps.

TypeScript 5.7 module resolution enforcement flow

TypeScript 5.7 module resolution enforcement flow

Node.js treats files with a .js extension differently depending on the nearest package.json's type field. When type: "module" is set, .js files are ESM. Without it, they're CommonJS. TypeScript 5.7's nodenext mode now enforces this distinction at compile time instead of allowing mismatches to slip through.

The implication here is that Express apps built with implicit CommonJS assumptions break immediately. Most legacy Express codebases don't declare type: "module" and use .ts files that compile to CommonJS .js outputs. When those apps import ESM-only packages or omit file extensions, TypeScript 5.7 stops compilation.

TypeScript module resolution comparison

TypeScript module resolution comparison

The Three Breaking Changes Hitting Express Apps Hard

The breaking changes cluster around three patterns that TypeScript previously allowed but Node.js would reject. Each pattern represents a common Express app structure that worked in TypeScript 5.6 but fails in 5.7 with nodenext enabled.

Three TypeScript 5.7 breaking change categories

Three TypeScript 5.7 breaking change categories

First, require() calls to ESM-only packages now fail at compile time. Many Express apps use require() to load dependencies synchronously during server initialization. When those dependencies are ESM-only, Node.js throws a runtime error. TypeScript 5.7 catches this earlier.

Second, importing JSON files without resolveJsonModule: true in tsconfig.json now produces a compile error. Express apps frequently import configuration files or package.json for version strings. The compiler no longer assumes JSON imports are valid without explicit configuration.

Third, relative imports missing the .js extension fail in nodenext mode. This catches developers off guard because TypeScript files use .ts extensions but must import with .js extensions when targeting ESM output. The mismatch between source and output extensions is a longstanding Node.js ESM requirement.

Error Case 1: require() Calls to ESM Modules Are Now Forbidden

The most common failure mode appears when Express apps attempt to require() an ESM-only package. This occurs frequently with newer middleware packages that dropped CommonJS builds.

// ❌ This fails in TypeScript 5.7 with nodenext
const helmet = require('helmet'); // Error: Cannot require() an ESM-only module

app.use(helmet());

The error message is explicit: "The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ESM module and cannot be imported with 'require'."

The fix requires either converting to dynamic import() or downgrading to a CommonJS-compatible package version:

// ✅ Option 1: Use dynamic import (requires async context)
const helmetPromise = import('helmet').then(m => m.default);

app.use(async (req, res, next) => {
  const helmet = await helmetPromise;
  return helmet()(req, res, next);
});

// ✅ Option 2: Use a CommonJS build (check package.json exports)
const helmet = require('helmet/dist/cjs/index.js');
app.use(helmet());

The tradeoff here is clear: dynamic imports add complexity but maintain forward compatibility. Pinning to CommonJS builds is simpler but locks you to older package versions. For production Express apps, the CommonJS approach typically wins because it avoids refactoring middleware initialization logic.

Error Case 2: Stricter JSON Import Rules Breaking Middleware Configs

Express apps routinely import JSON configuration files for environment-specific settings. TypeScript 5.7 now requires explicit compiler permission for these imports.

// ❌ Fails without resolveJsonModule: true
import config from './config.json';

app.listen(config.port);

The error states: "Cannot find module './config.json'. Consider using '--resolveJsonModule' to import module with '.json' extension."

The fix is straightforward but requires a tsconfig.json change that affects the entire project:

// tsconfig.json
{
  "compilerOptions": {
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "resolveJsonModule": true, // ✅ Add this
    "esModuleInterop": true
  }
}

// ✅ Now this works
import config from './config.json';

This matters because enabling resolveJsonModule changes how TypeScript treats all JSON imports project-wide. The compiler now validates JSON structure against the imported type, catching configuration errors at compile time instead of runtime.

JSON module resolution in TypeScript 5.7

JSON module resolution in TypeScript 5.7

Error Case 3: Missing .js Extensions in Import Paths Now Fail

The extension requirement trips up developers because TypeScript source files use .ts but must import with .js when targeting ESM. This reflects Node.js ESM behavior, not a TypeScript quirk.

// ❌ Fails in nodenext mode
import { UserService } from './services/user-service';

// ✅ Must include .js extension (even though file is user-service.ts)
import { UserService } from './services/user-service.js';

The error reads: "Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'nodenext'."

This breaking change forces explicit imports across the entire codebase. Automated tools help, but the migration still requires careful review to avoid breaking relative path structures. Teams often underestimate the scope—large Express apps can have hundreds of relative imports.

The Complete Fix: Migrating Your Express App to TypeScript 5.7

The migration path depends on whether your app can move to ESM or must remain in CommonJS. Most legacy Express apps stay in CommonJS until dependencies and tooling fully support ESM.

TypeScript 5.7 Express migration workflow

TypeScript 5.7 Express migration workflow

For CommonJS apps, the minimal fix preserves existing patterns while satisfying TypeScript 5.7:

// tsconfig.json for CommonJS apps
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "commonjs",           // Stay in CommonJS
    "moduleResolution": "node",     // Classic Node resolution
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "outDir": "./dist",
    "rootDir": "./src"
  }
}

This configuration avoids nodenext mode entirely, bypassing the strict ESM enforcement. The tradeoff is that you lose compile-time validation of Node.js ESM compatibility. For apps with no ESM migration timeline, this is the pragmatic choice.

For apps ready to migrate to ESM, the path requires coordinated changes across package.json, tsconfig.json, and every source file. The Node.js ESM migration guide covers the full process, but the core steps are:

  1. Set "type": "module" in package.json
  2. Set "module": "nodenext" in tsconfig.json
  3. Add .js extensions to all relative imports
  4. Convert all require() calls to import statements
  5. Update middleware initialization to handle async imports

The failure mode here is subtle but expensive: incomplete migrations leave the app in a broken state where some modules load correctly and others fail at runtime. Automated testing catches most issues, but edge cases in dynamic require() patterns often slip through.

When to Use --module nodenext vs commonjs in 2026

The decision between nodenext and commonjs depends on deployment constraints and dependency compatibility. Teams must evaluate both technical and organizational factors.

Module mode decision comparison for Express apps

Module mode decision comparison for Express apps

Use module: "commonjs" when:

  • The app has no near-term ESM migration plan
  • Critical dependencies lack ESM builds
  • The team prioritizes stability over forward compatibility
  • Deployment infrastructure doesn't support Node.js ESM yet

Use module: "nodenext" when:

  • The app is greenfield or actively maintained
  • All dependencies provide ESM builds
  • The team can handle the extension and async import requirements
  • You need compile-time validation of Node.js module compatibility

The distinction is critical for legacy Express apps: switching to nodenext without preparation breaks builds immediately. The compiler will surface every incompatible pattern at once, forcing emergency fixes or a rollback. Teams shipping to production need a staged migration with comprehensive testing before enabling nodenext.

For new Express apps in 2026, nodenext is the correct default. The Node.js ecosystem has largely moved to ESM, and TypeScript's stricter enforcement catches module errors before they reach production. The upfront cost of adding extensions and using async imports pays off in reduced runtime failures.

The Node.js 24 native TypeScript support enables running .ts files directly in production, but this only works when the TypeScript configuration matches Node.js's actual module behavior. Apps using nodenext mode get this compatibility automatically.

That covers the essential patterns for migrating Express apps to TypeScript 5.7's stricter module resolution. Apply these fixes in production and the difference will be immediate: fewer runtime module errors, clearer compile-time feedback, and forward compatibility with the Node.js ESM ecosystem. The TypeScript 6 release builds on these foundations, so getting the module configuration right now prevents future upgrade pain.