vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.01k stars 2.1k forks source link

When exporting a function and importing it through an alias: Failed to resolve import from ... . Does the file exist? #4148

Closed michaelcozzolino closed 2 months ago

michaelcozzolino commented 2 months ago

Describe the bug

in my vitepress project i am trying to use a component that uses an exported function and a type. the imports i tried are the following:

 import { test } from '@/test.ts';  // function import through alias not working
// import { test } from './test.ts'; // function, working
 import { A } from '@/testType.ts'; // working
// import { A } from './testType.ts'; // working

[plugin:vite:import-analysis] Failed to resolve import "@/test.ts" from "src/components/HelloWorld.vue". Does the file exist?

Reproduction

https://stackblitz.com/edit/vitejs-vite-xaqvvy?file=src%2Fcomponents%2FHelloWorld.vue

Expected behavior

All the imports i listed, should work

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (7) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vitepress: ^1.3.3 => 1.3.3

Additional context

No response

Validations

brc-dd commented 2 months ago

Your aliases are wrong and vite command is failing too. Also you haven't configured alias for vitepress.

brc-dd commented 2 months ago

https://stackblitz.com/edit/vitejs-vite-mbgzua?file=vite.config.ts,docs/.vitepress/config.ts