requirejs anonymous dependency not defined

懵懂的女人 提交于 2019-12-12 01:59:34

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/24079202/requirejs-anonymous-dependency-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!