Webpack错误解决(一):ERROR in Entry module not found

在webpack.config.js做了少许更改后,运行webpack命令,突然出现以下错误:

ERROR in Entry module not found: 
Error: Cannot resolve 'file' or 'directory'
./es6/index.es6 in E:\Workspace\webpack-template
 
 
  • 1
  • 2
  • 3

然而反复对比了目录结构,发现“es6/index.es6”就在“E:\Workspace\webpack-template”,但为什么始终找不到呢?试着引入path,将入口文件改为绝对地址,如下:

let path = require('path')
module.exports = {
    entry: {
        index: path.resolve('./es6/index.es6')
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

但依旧报同样的错误,“ERROR in Entry module not found”。

按配置逐项排除,最后发现竟然跟resolve配置项相关,覆盖默认配置后,必须在extensions中添加空字符串,如下:

resolve: {
    //  第一项空字符串必不可少,否则报模块错误
    extensions: ['', '.es6']
}
 
 
  • 1
  • 2
  • 3
  • 4

为什么会这样呢?官方的解释如下:

Using this will override the default array, meaning that webpack will no longer try to resolve modules using the default extensions. 
For modules that are imported with their extension, e.g. import SomeFile from "./somefile.ext", to be properly resolved, an empty string must be included in the array.
 
 
  • 1
  • 2

简单说起来,就是如果覆盖了默认的配置,就必须添加空字符串。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值