Files
gt-agent-company/.agents/skills/vue-best-practices/rules/module-resolution-bundler.md
sexygoat 3c62cc1cd1 first
2026-03-31 18:41:52 +08:00

2.1 KiB

title, impact, impactDescription, type, tags
title impact impactDescription type tags
moduleResolution Bundler Migration Issues HIGH fixes "Cannot find module" errors after @vue/tsconfig upgrade capability moduleResolution, bundler, tsconfig, vue-tsconfig, node, esm

moduleResolution Bundler Migration Issues

Impact: HIGH - fixes "Cannot find module" errors after @vue/tsconfig upgrade

Recent versions of @vue/tsconfig changed moduleResolution from "node" to "bundler". This can break existing projects with errors like "Cannot find module 'vue'" or issues with resolveJsonModule.

Symptoms

  • Cannot find module 'vue' or other packages
  • Option '--resolveJsonModule' cannot be specified without 'node' module resolution
  • Errors appear after updating @vue/tsconfig
  • Some third-party packages no longer resolve

Root Cause

moduleResolution: "bundler" requires:

  1. TypeScript 5.0+
  2. Packages to have proper exports field in package.json
  3. Different resolution rules than Node.js classic resolution

Fix

Option 1: Ensure TypeScript 5.0+ everywhere

npm install -D typescript@^5.0.0

In monorepos, ALL packages must use TypeScript 5.0+.

Option 2: Add compatibility workaround

{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "bundler",
    "resolvePackageJsonExports": false
  }
}

Setting resolvePackageJsonExports: false restores compatibility with packages that don't have proper exports.

Option 3: Revert to Node resolution

{
  "compilerOptions": {
    "moduleResolution": "node"
  }
}

Which Packages Break?

Packages break if they:

  • Lack exports field in package.json
  • Have incorrect exports configuration
  • Rely on Node.js-specific resolution behavior

Diagnosis

# Check which resolution is being used
cat tsconfig.json | grep moduleResolution

# Test if a specific module resolves
npx tsc --traceResolution 2>&1 | grep "module-name"

Reference