给 webpack-dev-server 提了个 bug

简介: 给 webpack-dev-server 提了个 bug

前言


背景是这样的,最近在全面整理 webpack 的配置项,为了加深理解和印象,会一个一个地选项去验证。今天看到 resolve 模块,然后发现了一个问题,所以有了 Modify webpack's resolve.mainFiles, resulting in an error when using webpack-dev-server #2801。


最终开发人员表示这确实是 bug,将在未来发布的 v4 版本修复。


关于提 ISSUE,由于需要外国友人看得懂,加上我蹩脚的英文,只能全程在谷歌翻译,尴尬哈哈

  • Operating System: macOS 10.15.7
  • Node Version: 12.12.0
  • NPM Version: 6.13.3
  • webpack Version: 4.41.2
  • webpack-dev-server Version: 3.9.0
  • Browser: It has nothing to do with the browser (Chrome)
  • This is a bug
  • This is a modification request


正文


Code


// webpack.config.js
module.exports = {
  // ...
  resolve: {
    mainFiles: ['fortest'] // Any name, as long as it is not 'index'
  }
}


// index.js(entry)
// The directory of components/button contains the fortest.js file
import Button from './components/button'


Expected Behavior


The resolve.mainFiles to be used while resolving directories.

When I import the button component as above, there should be no errors.


Actual Behavior


But the actual behavior is not the expected result, and the build fails with the following prompt:


ERROR in (webpack)-dev-server/client?http://localhost:8080
Module not found: Error: Can't resolve 'strip-ansi' in '/Users/frankie/Desktop/Web/Demo/Temp/temp_webpack/node_modules/webpack-dev-server/client'
 @ (webpack)-dev-server/client?http://localhost:8080 6:16-37
 @ multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./src/index.js


Guess


According to the error message, I found...


// node_modules/webpack-dev-server/client/index.js
// ...
var stripAnsi = require('strip-ansi');
// ...



// node_modules/strip-ansi/index.js
// ...
var ansiRegex = require('ansi-regex')();
// ...


I found the package.json of the two dependency packages strip-ansi and ansi-regex does not contain the main attribute, so it should look for index.js according to the default configuration of webpack. But now because I modified the resolve.mainFiles configuration to fortest, it should be fortest.js when parsing, but there is no fortest.js file for the two dependent packages. So an error was reported.


To verify my guess, I tried to modify it to:


// node_modules/webpack-dev-server/client/index.js
var stripAnsi = require('strip-ansi/index');
// node_modules/strip-ansi/index.js
var ansiRegex = require('ansi-regex/index')();


After the modification, this can be parsed normally without an error.

The button component can also be imported as expected


For Bugs; How can we reproduce the behavior?


A very simple configuration


// webpack.config.js
module.exports = {
  entry: './src/index.js'
  devServer: {
    contentBase: './dist',
    hot: true,
    open: true
  },
  resolve: {
    mainFiles: ['fortest'],
  },
  // Other irrelevant configuration...
}


// package.json
{
  "name": "temp_webpack",
  "version": "1.0.0",
  "description": "temp demo",
  "license": "MIT",
  "scripts": {
    "dev": "webpack-dev-server --config webpack.config.js --colors"
  },
  "devDependencies": {
    "clean-webpack-plugin": "3.0.0",
    "css-loader": "3.2.0",
    "file-loader": "5.0.2",
    "html-webpack-plugin": "3.2.0",
    "style-loader": "1.0.0",
    "webpack": "4.41.2",
    "webpack-cli": "3.3.10",
    "webpack-dev-server": "3.9.0"
  }
}


webpack allows us to modify the resolve.mainFiles configuration to specify the file name to be used when resolving the directory. But when I modify it, webpack-dev-server can't work normally.

Is this caused by my configuration error? Or is it a bug?


Thanks,


56.webp.jpg

目录
相关文章
|
数据安全/隐私保护 网络架构
DSL线路如何工作?
【4月更文挑战第15天】
1268 3
DSL线路如何工作?
|
API 网络架构 微服务
带你读《微服务架构设计模式》之三:微服务架构中的进程间通信
成功地开发基于微服务架构的应用软件,需要掌握一系列全新的架构思想和实践。在这本独特的书籍中,微服务架构的先驱、Java 开发者社区的意见领袖 Chris Richardson 收集、分类并解释了 44 个架构设计模式,这些模式用来解决诸如服务拆分、事务管理、查询和跨服务通信等难题。本书不仅仅是一个模式目录,还提供了经验驱动的建议,以帮助你设计、实现、测试和部署基于微服务的应用程序。
14238 0
|
10月前
|
人工智能 自然语言处理 网络安全
零门槛玩转OpenClaw(Clawdbot):阿里云10分钟一键部署+功能拓展全攻略
在智能办公与自动化需求爆发的2026年,OpenClaw(前身为Clawdbot、Moltbot)凭借自然语言指令执行、多工具集成、主流大模型兼容等核心优势,成为个人与轻量团队打造专属智能助手的首选工具。与普通聊天机器人不同,它堪称“7×24小时不下班的AI数字员工”,能轻松完成文件处理、日程管理、信息提取、跨工具协同等实操任务,大幅降低重复劳动成本。
761 8
|
9月前
|
人工智能 弹性计算 自然语言处理
OpenClaw怎样部署?阿里云推出快速部署方案,三步拥有超级AI助理!
阿里云推出OpenClaw(原Clawdbot)快速部署方案:7×24小时在线的“AI数字员工”,支持代码编写、文档处理、邮件管理、日程安排及多IM协同。三步即可完成部署——购服务器、配百炼密钥、图形化配置,零代码、高安全、全场景覆盖。
439 8
|
10月前
|
域名解析 开发框架 .NET
从零开始:注册域名、租用主机并部署PageAdmin CMS完整教程
本文详细介绍了注册域名、租用虚拟主机、上传PageAdmin CMS并完成网站部署的全流程。从域名查询购买、主机环境配置到程序安装,提供完整的操作指南,帮助新手顺利完成网站上线。
895 5
|
SQL 数据可视化 数据挖掘
云上 · 百炼 MCP 数据分析与可视化 Demo 实战
一套跑在阿里云百炼上的“生成 SQL → 执行 → 分析 → 出图”闭环方案,端到端无本地依赖,可发布为组件/网页对外服务。
1137 8
|
JSON Shell Linux
配置Python的环境变量可
配置Python的环境变量
1485 4
|
分布式计算 监控 大数据
如何优化Spark中的shuffle操作?
【10月更文挑战第18天】
|
测试技术 语音技术 Android开发
起飞,纯本地实时语音转文字!
起飞,纯本地实时语音转文字!
1425 3
|
算法 程序员
理解操作系统内存管理:页面置换算法全解析
大家好,我是小米,热爱分享技术的大哥哥!今天聊的是操作系统中的页面置换算法。它解决的是内存满载时,如何选择合适的页面移出以腾出空间的问题。主要有三种算法:FIFO(先进先出),简单但性能不佳;LRU(最近最久未使用),考虑时间局部性,性能较好但实现较复杂;OPT(最佳置换),理论上最优但无法实际应用。这些算法各有千秋,在实际应用中需根据场景选择最合适的方案。希望这能帮大家更好地理解内存管理的核心机制!
1110 2