Webpack:在缺少成员导入时引发错误 [英] Webpack: Throw error on missing member import
本文介绍了Webpack:在缺少成员导入时引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的导入:
import { foo } from 'bar';
如果 foo
没有定义,有没有办法让 Webpack 抛出错误?
Is there a way to get Webpack to throw an error if foo
is not defined?
请注意,如果这有所不同,我将使用 Babel.
推荐答案
As Tobias K 在评论中指出,另一个答案是不正确的.如果您尝试导入不存在的模块,配置 strictModuleExceptionHandling: true
不会产生编译时错误.
As Tobias K pointed out in the comments, the other answer is incorrect. Configuring strictModuleExceptionHandling: true
will not produce a compile time error if you try to import a module which does not exist.
正确的配置是strictExportPresence: true
,仅在webpack v2.3.0及更高版本中可用.(早期版本只能显示警告,不能显示错误.)
The correct configuration is strictExportPresence: true
, which is only available in webpack v2.3.0 and later. (Earlier versions can only show a warning, not an error.)
这篇关于Webpack:在缺少成员导入时引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文