Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] vue 项目中,引入 src 目录下的 组件 报错 ts(2307) #1377

Closed
WangJincheng4869 opened this issue Jul 5, 2023 · 8 comments
Labels
question Asking question

Comments

@WangJincheng4869
Copy link

Description

我是在 vue 项目中使用文档,如果引用 docs\.vuepress\components 下的组件是没有问题的

但是如果 引入 src\components 下的组件就会报错 ts(2307)

image

Reproduction

https://github.com/WangJincheng4869/fanKuiWenJian/blob/main/vuepress-next-bug.zip

Used Package Manager

pnpm

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 16.30 GB / 31.56 GB
  Binaries:
    Node: 18.14.2 - D:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 9.2.0 - D:\Users\jcwang\AppData\Roaming\npm\npm.CMD
  Utilities:
    Git: 2.41.0.
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.22621.1928.0), Chromium (114.0.1823.58)
  npmPackages:
    @vuepress/bundler-vite: 2.0.0-beta.63 => 2.0.0-beta.63
    @vuepress/plugin-search: Not Found
    @vuepress/plugin-shiki: Not Found
    @vuepress/plugin-theme-data: Not Found
    @vuepress/plugin-toc: Not Found
    @vuepress/shared: Not Found
    @vuepress/theme-default: Not Found
    @vuepress/utils: Not Found
    vue: ^3.3.4 => 3.3.4
    vue-loader: Not Found
    vue-router: ^4.2.2 => 4.2.2
    vuepress: 2.0.0-beta.63 => 2.0.0-beta.63
    vuepress-vite: Not Found
    vuepress-webpack: Not Found
@Mister-Hope
Copy link
Member

Mister-Hope commented Jul 5, 2023

I don't think you have a valid tsconfig, if you want volar to recognize your vue files, you should include them all in tsconfig.json.

This is likely (99.9%) to be an issue that you are not configuring your vue vscode extensions well as they require. So you may ask for help in other places, there is no difference a VuePress projects differs from normal vue projects, the only one you should be aware of is that .vuepress/config.ts and other files it's importing is the same as vite.config.ts which should have node env(@types/node), while other files are running under browsers, which you should enable DOM lib.

@Mister-Hope Mister-Hope added the question Asking question label Jul 5, 2023
@WangJincheng4869
Copy link
Author

I don't think you have a valid tsconfig, if you want volar to recognize your vue files, you should include them all in tsconfig.json.

我尝试加入 docs/**/*.vue 但是没用啊

image

@WangJincheng4869
Copy link
Author

I don't think you have a valid tsconfig, if you want volar to recognize your vue files, you should include them all in tsconfig.json.

This is likely (99.9%) to be an issue that you are not configuring your vue vscode extensions well as they require. So you may ask for help in other places, there is no difference a VuePress projects differs from normal vue projects, the only one you should be aware of is that .vuepress/config.ts and other files it's importing is the same as vite.config.ts which should have node env(@types/node), while other files are running under browsers, which you should enable DOM lib.

兄弟!我知道你英文很好,但是我英文很差,我知道你写英文是为了照顾国外友人,但是中国友人能不能也照顾一下啊。翻译后来的内容有点乱啊....

@Mister-Hope
Copy link
Member

Mister-Hope commented Jul 5, 2023

我认为你没有有效的 tsconfig,如果你想让 volar 识别你的 vue 文件,你应该将它们全部包含在 tsconfig.json 中。

这很可能 (99.9%) 是因为您没有按照要求配置 vue vscode 扩展的问题。 所以你可能会在其他地方寻求帮助,VuePress 项目与普通 vue 项目没有区别,你唯一应该注意的是 .vuepress/config.ts 和它导入的其他文件与 vite.config.ts 相同。,应该有 node 环境 (@types/node);而其他文件在浏览器下运行,您应该在 lib 中启用 DOM。

@WangJincheng4869
Copy link
Author

我认为你没有有效的 tsconfig,如果你想让 volar 识别你的 vue 文件,你应该将它们全部包含在 tsconfig.json 中。

这很可能 (99.9%) 是因为您没有按照要求配置 vue vscode 扩展的问题。 所以你可能会在其他地方寻求帮助,VuePress 项目与普通 vue 项目没有区别,你唯一应该注意的是 .vuepress/config.ts 和它导入的其他文件与 vite.config.ts 相同。 ,应该有 node 环境 (@types/node);而其他文件在浏览器下运行,您应该在 lib 中启用 DOM。

非常感谢!你能照顾一下我这个英文很垃圾的中国人。

@Mister-Hope
Copy link
Member

Another thing is that Volar do not auto update analyze in all cases, after editing tsconfig.json, d.ts or something related, you should F1 and type volar: restart vue server.

另一件事是 Volar 不会在所有情况下自动更新分析,编辑 tsconfig.json、d.ts 或相关内容后,您应该“F1”并输入“volar: restart vue server”。

@WangJincheng4869
Copy link
Author

Another thing is that Volar do not auto update analyze in all cases, after editing tsconfig.json, d.ts or something related, you should F1 and type volar: restart vue server.

另一件事是 Volar 不会在所有情况下自动更新分析,编辑 tsconfig.json、d.ts 或相关内容后,您应该“F1”并输入“volar: restart vue server”。

非常感谢!原因找到了。但不知道是 Volar 的原因还是 TS 的规则,当使用 docs/**/*.vue 配置时,里面目录名使用 . 开头的都不识别,只要配置为 docs/.vuepress/**/*.vue 就可以了。

@Mister-Hope
Copy link
Member

This could be helpful to others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking question
Projects
None yet
Development

No branches or pull requests

2 participants