问题描述
在我升级到 webpack beta 23 之后,我开始在运行 webpack 时遇到与 extensions 属性有关的错误:
After I have upgraded to webpack beta 23 I have started getting an error to do with the extensions property when running webpack:
- configuration.resolve.extensions[0] 不应为空.
我的扩展名是: extensions: ['','.ts', '.js'],
my extensions were: extensions: ['','.ts', '.js'],
如果我删除空白扩展选项,配置错误就会消失,但现在我的模块都不会加载,因为它们都是在没有扩展的情况下加载的.在这个新版本中,我应该以某种特定的方式指定空白扩展名吗?
If I remove the blank extension option the configuration error goes away but now none of my modules will load as they are all loaded without an extension. Is there some specific way I should be specifying blank extension in this new version?
我想我找到了正确的配置
我不确定这是否正确,但经过一系列试验后出现错误,我尝试使用 * 符号而不是空字符串.这似乎解决了这个问题.所以 extensions 属性的最终语法:
I am not sure that this is correct but after a series of trial an error I have tried using the * symbol instead of an empty string. This seems to have fixed the problem.So final syntax for the extensions attribute:
扩展名:['*', 'js', 'ts']
extensions: ['*', 'js', 'ts']
希望这是预期的方式
推荐答案
只是为了确认您的发现.
Just to confirm your findings.
不推荐使用空字符串:https://github.com/webpack/webpack/issues/3043
extensions: ['.ts', '.js']
将解析您的所有 .ts 和 .js 文件,而不是更多.
extensions: ['.ts', '.js']
will resolve all of your .ts and .js files, not more.
extensions: ['*', '.ts', '.js']
将解析所有扩展名.
这篇关于升级到 Webpack beta 23 后,我不能再使用空白扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!