webpack 4 将多个入口点指定为对象时警告无效配置对象
webpack 4 warns of invalid configuration object when specifying multiple entry points as objects
我正在尝试将我的应用拆分为依赖于同一模块的两个块。我正在关注官方 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,并使用此功能拆分块:
- Prevent Duplication(对于 webpack v4)。
- 将 webpack 升级到 v5(目前仍处于 BETA 状态);
我正在尝试将我的应用拆分为依赖于同一模块的两个块。我正在关注官方 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,并使用此功能拆分块:- Prevent Duplication(对于 webpack v4)。
- 将 webpack 升级到 v5(目前仍处于 BETA 状态);