vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.16k stars 922 forks source link

[Bug report] 开发环境下,修改文件 `permalink` 会导致 `Failed to resolve import "xxx"` #1526

Closed pengzhanbo closed 2 months ago

pengzhanbo commented 2 months ago

Description

启动开发服务后,对 markdown 文件 frontmatter 字段的 permalink 进行修改,保存文件后,均会导致错误。

错误信息:

[plugin:vite:import-analysis] 
Failed to resolve import "/home/projects/vuepress-lc5skn/docs/.vuepress/.temp/pages/ff/ff/ff/index.html.js" 
from "docs/.vuepress/.temp/internal/routes.js". 
Does the file exist?

在重现中,修改 docs/permalink.md 文件即可重现该问题。

Reproduction

https://stackblitz.com/edit/vuepress-lc5skn?file=docs%2FREADME.md

Used Package Manager

pnpm

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
    bun: Not Found
  Utilities:
    Git: Not Found
  Browsers:
    Chrome: Not Found
  npmPackages:
    @vuepress/bundler-vite: 2.0.0-rc.9 => 2.0.0-rc.9 
    @vuepress/bundler-webpack: Not Found
    @vuepress/cli: Not Found
    @vuepress/client: Not Found
    @vuepress/core: Not Found
    @vuepress/markdown: Not Found
    @vuepress/shared: Not Found
    @vuepress/utils: Not Found
    vue: ^3.4.21 => 3.4.21 
    vue-router: Not Found
    vuepress: 2.0.0-rc.9 => 2.0.0-rc.9
Mister-Hope commented 2 months ago

I believe this issue is related to vite, as I can trigger similar issue on a normal HMR of .vue component

pengzhanbo commented 2 months ago

我尝试在 vuepress 旧版本中重现该问题,发现在 rc.7 之前的版本无该问题,从 rc.8 开始出现该问题, v2.0.0-rc.7...v2.0.0-rc.8 在 diff 中也未发现 潜在的引发该问题的代码修改。

在这两个版本之间,vite 版本 确实发生了 更新 , 因此我相信 该问题跟 vite 有关 是对的。

meteorlxy commented 2 months ago
  bundler: viteBundler({
    viteOptions: {
      server: {
        fs: {
          cachedChecks: false,
        },
      },
    },
  }),

Ref: https://github.com/vitejs/vite/issues/15784#issuecomment-1923683823

I just tried the snippet above in your repro link, and it's working well then. Not sure if we should set it as the default in bundler-vite pkg

Mister-Hope commented 2 months ago

I think we should set it as default value

NeonGooRoo commented 2 months ago
  bundler: viteBundler({
    viteOptions: {
      server: {
        fs: {
          cachedChecks: false,
        },
      },
    },
  }),

Ref: vitejs/vite#15784 (comment)

I just tried the snippet above in your repro link, and it's working well then. Not sure if we should set it as the default in bundler-vite pkg

I have an issue in dev mode.

I added the code above, as well as import { viteBundler } from '@vuepress/bundler-vite' into theme.ts, it fixed the problem until I added new media again. After that, I just need to save the config.ts ts again (with no changes), so VScode restarts dev mode and problem fixes again.

Mister-Hope commented 2 months ago

theme.ts

Are you sure you are doing the correct thing?

NeonGooRoo commented 2 months ago

theme.ts

Are you sure you are doing the correct thing?

I actually have no idea, sorry, I have no idea how Vue actually works and I have 0 programming experience