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

Cannot find module '~virtual/svg-component' or its corresponding type declarations. #18

Open
gradyll opened this issue Mar 14, 2024 · 11 comments

Comments

@gradyll
Copy link

gradyll commented Mar 14, 2024

I built vue2 in webpack5 using typescript patterns, and when introducing ~virtual/svg-component in main.ts, Cannot find module '~virtual/svg-component' or its corresponding type declarations is displayed. You should add a type declaration to the webpack.

@Jevon617
Copy link
Owner

Have you set dts=true?

@upleave
Copy link

upleave commented Oct 22, 2024

Have you set dts=true?

设置了还是报一样的错误
这是我vite.config.ts的配置:
image

这是我tscofign.app.json的配置:
image

@Jevon617
Copy link
Owner

@upleave 可以提供一个最小的复现demo吗?

@upleave
Copy link

upleave commented Oct 22, 2024

@upleave 可以提供一个最小的复现demo吗?

svg-component.d.ts 和 svg-component-global.d.ts 文件生成出来后就没问题了,可能是我添加dts:true之后要等一阵才能生成完。

谢谢解答!

@heavenly-zy
Copy link

svg-component.d.ts 和 svg-component-global.d.ts 文

你好,请问 svg-component.d.tssvg-component-global.d.ts 这两个文件是自动生成的嘛,我设置dts:true后,发现并没有自动生成这两个文件

@Jevon617
Copy link
Owner

@heavenly-zy 试试设置 dtsDir, 看下该目录下会生成不, 如果不能, 就提供一个最小的复现demo给我, 感谢!

@heavenly-zy
Copy link

@heavenly-zy 试试设置 dtsDir, 看下该目录下会生成不, 如果不能, 就提供一个最小的复现demo给我, 感谢!

设置了 dtsDir 也还是不行,不知道是不是被其他依赖影响了,demo 在这儿

@Jevon617
Copy link
Owner

@heavenly-zy 需要启动之后访问项目才会生成, 因为是在 configureServer 钩子生成的 type.

image

@heavenly-zy
Copy link

heavenly-zy commented Nov 27, 2024

@heavenly-zy 需要启动之后访问项目才会生成, 因为是在 configureServer 钩子生成的 type.

image

好的,感谢,现在可以了,之前我一直以为是只要开启了 dev server 就会生成,才知道还需要访问页面;这个有办法优化为只要开启 dev server 就生成吗?

@Jevon617
Copy link
Owner

确实是可以这样优化的.

@Jevon617
Copy link
Owner

@heavenly-zy 最新版本已优化为开启server 就会生成.

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

No branches or pull requests

4 participants