Why is define undefined in a module using requirejs

227 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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