Skip to content

tsconfig baseUrl bare imports (no paths) are not resolved → ERR_MODULE_NOT_FOUND at SSR #4

Description

@hyf0

Problem

tsconfig baseUrl bare imports (with no paths) are not resolved.

react.dev's tsconfig.json sets "baseUrl": "src" and imports modules bare, e.g. import {Page} from 'components/Layout/Page'. Next/SWC resolves these. Under vinext every page 500s at SSR:

Error: Cannot find module 'components/Layout/Page' imported from src/pages/[...markdownPath].js
  code: 'ERR_MODULE_NOT_FOUND'

Root cause (from reading vinext source)

  • config/tsconfig-paths.ts only materializes aliases for compilerOptions.paths — a baseUrl-only project produces zero aliases.
  • config/next-config.ts only enables Vite's native resolve.tsconfigPaths when useNativeTsconfigPaths = isTypeScriptConfig && viteMajor >= 8. react.dev's config is next.config.js (not .ts), so it's disabled.
  • Net: bare baseUrl roots resolve nowhere.

Workaround used

Manual resolve.alias for the bare-imported roots (components, utils, hooks) → absolute src/<root>/.

Suggested fix

Honor compilerOptions.baseUrl (bare-root resolution, not just paths) for the app, regardless of whether next.config is .js or .ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1: highReal bug, cheap fix, do soonarea: configConfig / module resolutionupstream: unfiledNeeds an issue/PR filed on cloudflare/vinext

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions