在TS中引用路径别名提示找不到模块或者相应的声明
ts文件中使用webpack配置好的路径别名,出现报错
![](https://i-blog.csdnimg.cn/blog_migrate/969ba069872f6609c683b5a6079452ef.png)
在vue中,正常情况下都是在webpack的webpack.config.js文件中进行配置别名的,但这里没效果。
但是在vue后缀文件中的style样式里就可以用。script里面还是报错的
![](https://i-blog.csdnimg.cn/blog_migrate/1c5cb72008857982d73d9d6120f9f852.png)
原因:在项目中启用TS,会让webpack配置文件中的路径别名配置失效
解决方案:
在两边同时配置别名
在tsconfig.json文件中配置别名
![](https://i-blog.csdnimg.cn/blog_migrate/67332a968848adeac89049aac65c1c5f.png)
在webpack.config.js配置文件中设置
![](https://i-blog.csdnimg.cn/blog_migrate/27879f53eaa281d4c837957c51357872.png)