You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo项目中VS Code无法识别模块别名问题求助

Fix VS Code Not Recognizing Import Aliases in Your Expo Project

Let's break down why VS Code isn't picking up your alias and fix it step by step:

1. Fix the tsconfig.json Paths Pattern

The root issue here is a mismatch between your alias configuration in tsconfig.json and how you're actually using the alias in code.

Your current tsconfig.json has:

"paths": { "home": ["./"] }

This only matches top-level imports like import "home" — it won't recognize subpath imports like home/src/thing. You need to add a wildcard to the pattern to cover all nested paths under the alias:

Update your tsconfig.json's paths section to:

"paths": { 
  "home/*": ["./*"] 
}

Since you're working with a TypeScript project (you have a tsconfig.json), VS Code prioritizes this file for language service intellisense. Having both tsconfig.json and jsconfig.json can sometimes create conflicts. You have two options:

  • Delete jsconfig.json entirely (it's unnecessary for TypeScript projects), or
  • Update its paths to match the corrected tsconfig.json pattern to keep consistency:
    "paths": { "home/*": ["./*"] }
    

3. Refresh VS Code's TypeScript Service

Config changes don't always take effect immediately in VS Code. Force a refresh by:

  • Opening the command palette (press Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on Mac)
  • Searching for and running the command: TypeScript: Restart TS Server
  • If that doesn't work, restart VS Code entirely

4. Verify the Fix

After making these changes, go back to your import Thing from "home/src/thing"; statement — VS Code should now recognize the path, let you jump to the file, and stop showing "cannot find module" errors.

Note: Your Babel config is already set up correctly (since the project compiles fine), so we don't need to adjust that part. The problem was purely with VS Code relying on the TypeScript config for intellisense.

内容的提问来源于stack exchange,提问作者Evanss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:22:34