javascriptrequirejsundefinedrequirejs-define

Why is define undefined in a module using requirejs


I use requirejs, I have this script tag

<script data-main="{{asset('/libs/js/main')}}" src="{{asset('/libs/js/requirejs/require.js')}}"></script>

In my main.js I load this

require(['test'], function(_){
  ...
})

In the main.js define is defined.

My test.js looks like this

(function(){
  console.log(define);
  ...
}());

But inside the test.js if I run this console.log(define) I get undefined. Why, shouldn'T define be defined? The actual defining works like a charm, no errors. Scripts are loading.


Solution

  • Okay, the problem was, that everything was within an IIFE. Removing this solved my problem.

    EDIT: Now that I understand the problem, it is a duplicate of this one.

    requirejs anonymous dependency not defined