webpack.ProvidePlugin or typescript配置问题
本文介绍了webpack.ProvidePlugin or typescript配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
想使用webpack.ProvidePlugin全局使用lodash:
webpack中plugin配置
new webpack.ProvidePlugin({
_: "lodash"
})
在ts中使用
_.toUpper("hello")
webpack打包结果
ERROR in ./src/utils.ts
(9,10): error TS2686: '_' refers to a UMD global, but the current file is a module. Consider adding an import instead.
看错误的提示,需要我手动引用模块。但是实际上打包结果跑着的是OK的,求解。
解决方案
首先结果可以是因为在webpack.config.js中配置了,lodash会被打包至项目:
vendor: [
"lodash"
]
上述的错误原因是由于ts中没有发现找到'_'模块的引入,但是默认会以any类型引入,所以加上:
declare var _:any;
这篇关于webpack.ProvidePlugin or typescript配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文