gpt4 book ai didi

javascript - kurento-client-js 的 Webpack 构建中的循环引用

转载 作者:数据小太阳 更新时间:2023-10-29 04:52:03 25 4
gpt4 key购买 nike

我在尝试使用 Webpack 2 + babel 构建 kurento-client-js 时遇到错误。

WARNING in ./node_modules/kurento-client/lib/register.js
60:20-33 Critical dependency: the request of a dependency is an expression

执行结果为

Uncaught Error: Cannot find module "."

我认为问题本身是由 /lib/register.js 中的 require 引起的

//kurento-clinet/lib/register.js
if (constructor == undefined)
return register(require(name));

以及导致错误的代码:

//kurento-clinet/lib/index.js
//this module requires kurento-client resulting in circular reference
register('kurento-client-core')

kurento bower 包包含使用 browserify 构建的分布式。

我想知道是否有人尝试使用 webpack 构建 kurento-client-js。请分享您的经验。

编辑:

循环依赖错误堆栈跟踪:

Uncaught TypeError: Cannot read property 'MediaObject' of undefined
at Object._typeof (KurentoClient.js:42)
at __webpack_require__ (bootstrap 0d7eac46304670c5f3b5:19)
at Object._typeof (index.js:44)
at __webpack_require__ (bootstrap 0d7eac46304670c5f3b5:19)
at Object.module.exports (HubPort.js:21)
at __webpack_require__ (bootstrap 0d7eac46304670c5f3b5:19)
at Object._typeof (index.js:32)
at ...

最佳答案

首先,webpack 提示动态依赖(在构建包时无法解决)。它不是循环依赖。

我是这样工作的:

1) 在您应用的 main.js 中手动需要 register() 函数可能需要的所有模块

require('kurento-client-core')
require('kurento-client-elements')
require('kurento-client-filters')

const kc = require('kurento-client-core/lib/index.js')

console.log(kc)

2) 使用这个 webpack 插件完全忽略未解析/动态的 require() 调用

//in webpack.config.js
plugins:[

function() {
this.parser.plugin('call require', function(expr) {
if (expr.arguments.length !== 1) {
return;
}

const param = this.evaluateExpression(expr.arguments[0]);
if (!param.isString() && !param.isConditional()) {
return true;
}
});
}
//... other plugins
]

Webpack2 会警告旧的插件格式,但它确实有效

致谢名单: https://stackoverflow.com/a/42527120/646156

关于javascript - kurento-client-js 的 Webpack 构建中的循环引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45651246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com