webpack - 将多个入口点指定为对象时,webpack 4 警告配置对象无效
问题描述
我正在尝试将我的应用程序分成两个依赖于同一模块的块。我正在关注官方 webpack 文档,该文档描述了如何通过创建多个入口点来实现这一点,如下所示:
module.exports = {
entry: {
index: {
import: "./src/index.js",
dependOn: "oidcclient"
},
callback: {
import: "./src/callback.js",
dependOn: "oidcclient"
},
oidcclient: "./src/oidc-client"
},
...
当我尝试构建时,上面的配置给了我以下错误:
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.entry should be one of these:
function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]
-> The entry point(s) of the compilation.
Details:
* configuration.entry['callback'] should be a string.
-> The string is resolved to a module which is loaded upon startup.
* configuration.entry['callback'] should be an array:
[non-empty string]
-> A non-empty array of non-empty strings
* configuration.entry['callback'] should be one of these:
[non-empty string]
-> All modules are loaded upon startup. The last one is exported.
* configuration.entry['callback'] should be one of these:
non-empty string | [non-empty string]
-> An entry point with name
如果我删除了 callbackk 的入口点,并将 index 与 oidcclient 一起保留,那么我会收到类似的 index 错误而不是 callback。
我几乎是从官方文档中复制粘贴一个示例,这让我对可能导致这种情况的原因感到困惑。任何帮助深表感谢。
解决方案
问题的原因是:你使用了 webpack v5 的一个特性。
所以,你有两种方法可以解决这个问题:
- 将后面的值
entry
恢复为strings,并使用此功能拆分块:- 防止重复(对于 webpack v4)。
- 将 webpack 升级到 v5(目前仍处于 BETA 状态);
推荐阅读
- javascript - 我怎样才能让我在 Canvas 中的两个图像不会相互擦除?
- azure-devops - Asp.net 核心应用程序,##[error]Error: No package found with specified pattern: D:\a\r1\a\**\*.zip 我得到这个错误
- javascript - array.reduce() 方法中这种语法的含义是什么?
- python - 查找 777 个文件和文件夹的脚本如何改进并使其在 python 2.4 (RHEL5) 中兼容
- python - 除以两个输出 0 而不是期望的结果
- elasticsearch - 即使在 AWS ElasticSearch 中超过父断路器限制后,断路器也不会触发
- r - 当这两个词被其他词包围时,是否有可能匹配字符中的两个词?
- apache-spark - 如何在 AWS DyanmoDB 上执行 ETL 作业以仅在使用 AWS Glue 的新数据上获取 S3 中的 csv 文件
- java - 检查所有 Dto 成员中的空条件。如果不是,则将该值设置为 pojo 类的相同属性
- mysql - 调用 MySql 存储过程