我正试图将我的应用程序拆分为依赖于同一模块的两个块。我正在关注官方的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的入口点,并将索引与oidcclient一起保留,那么我会收到类似的索引错误,而不是回调错误。
我几乎是在复制粘贴官方文档中的一个例子,这让我很困惑是什么导致了这种情况。非常感谢您的帮助。
问题的原因是:您使用了webpack v5的一个功能。
所以,你有两种方法来解决这个问题:
- 将
entry
中的值还原回字符串,并使用此功能拆分块:- 防止重复(适用于webpack v4(
- 将webpack升级到v5(目前仍处于BETA状态(