wxt-dev / wxt-dev/wxt

TypeScript path aliases (@) don't work - WXT generates incorrect paths in .wxt/tsconfig.json

Open
#1,828 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending-triage
Dominant language
TypeScript
Stars
10.5k
Forks
564
PR merge metrics
No merged PRs in 30d

Description

When configuring TypeScript path aliases (like @ for src folder) in a WXT project, the build fails because WXT generates incorrect path mappings in .wxt/tsconfig.json.

The generated paths point to the project root instead of the actual source directory:

Generated by WXT (incorrect):

  ```json
  {
    "paths": {
      "@": [".."],        // Points to project root
      "@/*": ["../*"]     // Points to project root
    }
  }

  Expected (correct):
  {
    "paths": {
      "@": ["../src"],      // Should point to src folder
      "@/*": ["../src/*"]   // Should point to src folder
    }
  }

  This causes imports like import { logger } from '@/utils/logger' to fail with:
  [plugin:wxt:bundle] Could not load /home/pavelbe/Projects/PriceTrackers/PriceDrop/utils/logger


------


Expected Behavior

  - WXT should respect the alias configuration and generate correct paths in .wxt/tsconfig.json
  - The generated paths should point to ../src not ..
  - Imports using @ alias should resolve correctly
  - Build should complete successfully

  Actual Behavior

  - WXT generates paths pointing to project root (..) instead of src folder (../src)
  - All imports using @/ fail with "Could not load" errors
  - Build fails completely
  - Only workaround is to use relative imports

  Additional Context

  What I've tried (nothing worked):

  1. Using vite-tsconfig-paths plugin
  2. Configuring Vite's resolve.alias directly
  3. Removing extends: "./.wxt/tsconfig.json" from tsconfig.json
  4. Various combinations of baseUrl and paths
  5. Using both alias in wxt.config.ts and vite config

  Current workaround:

  Replace all imports with relative paths:
  // ❌ Doesn't work
  import { logger } from '@/utils/logger';

  // ✅ Works but not ideal for large projects
  import { logger } from '../utils/logger';

### Reproduction

Reproduction

  wxt.config.ts:
  import { defineConfig } from 'wxt';
  import { resolve } from 'path';

  export default defineConfig({
    modules: ["@wxt-dev/module-react", "@wxt-dev/i18n/module"],
    alias: {
      '@': resolve(__dirname, 'src'),
      '~': resolve(__dirname),
    },
  });

  tsconfig.json:
  {
    "compilerOptions": {
      "target": "ES2022",
      "lib": ["ES2022", "dom"],
      "jsx": "react-jsx",
      "module": "ESNext",
      "moduleResolution": "Bundler",
      "baseUrl": ".",
      "paths": {
        "@/*": ["./src/*"],
        "~/*": ["./*"]
      }
    }
  }

  Component using alias:
  // src/components/MyComponent.tsx
  import { logger } from '@/utils/logger';  // ❌ Fails

  export function MyComponent() {
    return <div>Test</div>;
  }

### Steps to reproduce

Steps to reproduce

  1. Configure aliases in wxt.config.ts as shown above
  2. Add path mappings to tsconfig.json
  3. Create any component that imports using @/ alias
  4. Run bun run build
  5. Build fails with module resolution error

### System Info

```shell
System:
    OS: Linux 6.6 Ubuntu 24.04.2 LTS
    CPU: (6) x64 Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
    Memory: 7.80 GB / 15.59 GB
    Container: Yes (WSL)
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.16.0 - /usr/bin/node
    npm: 11.4.1 - ~/.npm-global/bin/npm
    bun: 1.2.13 - ~/.npm-global/bin/bun

  Package versions:
    wxt: 0.20.7
    typescript: 5.7.3
    react: 19.0.0
    @wxt-dev/module-react: 1.1.1
    @wxt-dev/i18n: 1.1.0

  Used Package Manager
  bun
Used Package Manager

bun

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the wxt.config.ts and tsconfig.json reproduction, then inspect how WXT produces .wxt/tsconfig.json path mappings. Compare the generated mappings for @ and ~ with the expected ../src and ../ paths, and verify completion by running bun run build with the alias import from the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.