【发布时间】:2022-12-21 23:29:22
【问题描述】:
节点版本:18.12.1 角度版本:15.0.4
我正在使用 import.meta.webpackContext 但我收到此控制台错误:
{}.webpackContext is not a function
我将此函数调用包装在 if 语句中以避免错误,但它仍在进入。谁能解释我错过了什么?
console.log("AAA: import meta webpackContext: ", import.meta.webpackContext);
if (import.meta.webpackContext) {
console.log("AAA: but entered here");
importAll(import.meta.webpackContext('./services/', ESM_CONFIG));
importAll(import.meta.webpackContext('./components/', ESM_CONFIG));
importAll(import.meta.webpackContext('./directives/', ESM_CONFIG));
importAll(import.meta.webpackContext('./filters/', ESM_CONFIG));
importAll(import.meta.webpackContext('./native-extensions/', ESM_CONFIG));
importAll(import.meta.webpackContext('./prototypes/', ESM_CONFIG));
importAll(import.meta.webpackContext('./views/', ESM_CONFIG));
} else {
console.log("AAA: should enter here");
}
从屏幕截图中,您可以看到它正在记录未定义的日志,但最终出现在 if 块而不是 else 块中。