requirejs匿名依赖未定义 [英] requirejs anonymous dependency not defined
本文介绍了requirejs匿名依赖未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的设置如下:
var lib = function(){...};
define(function(){
return lib;
});
模块定义如下
var mod = function(){
...
lib('para')...
};
define([lib / lib],function(lib){
return mod;
});
在我的main.js中我有这个
require(['lib / lib'],function(lib){
lib('para')。mod();
})
问题: Lib在main.js中可用,但对于mod,我收到错误未获取 ReferenceError:lib未定义
解决方案
所以实际的问题是一切都在IIFE之内。这导致定义
不可用,这导致在else部分中的If子句解析。
Window.define
可用,所以传递给IIFE可以解决我的问题。
I have a problem with requirejs and a dependency being undefined.
My setup is the following:
var lib = function (){...};
define(function() {
return lib;
});
And the modules are define like this
var mod = function (){
...
lib('para') ...
};
define(["lib/lib"], function(lib) {
return mod;
});
In my main.js I have this
require(['lib/lib'], function(lib){
lib('para').mod();
})
The Problem: Lib is available in main.js but for mod I get an error Uncaught ReferenceError: lib is not defined
解决方案
So the actual problem was that everything was within an IIFE. This leads to define
not being available, which leads to the If clause resolving in the else part.
Window.define
is available however, so passing this to the IIFE solves my issue.
这篇关于requirejs匿名依赖未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文