Attention
TYPO3 v12 has reached end-of-life as of April 30th 2026 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v12 here: TYPO3 ELTS.
Dependency handling
Attention
Deprecated since version 12.0
The RequireJS project has been discontinued and was therefore replaced by native ECMAScript v6/v11 modules in TYPO3 v12.0. The infrastructure for configuration and loading of RequireJS modules is deprecated with v12.0 and will be removed in TYPO3 v13. See RequireJS to ES6 migration.
Let us try to explain the dependency handling with the most used JS lib: jQuery
To prevent the "$ is undefined" error, you should use the dependency handling of RequireJS. To get jQuery working in your code, use the following line:
define(['jquery'], function($) {
// in this callback $ can be used
});
The code above is very easy to understand:
- every dependency in the array of the first argument
- will be injected in the callback function at the same position
Let us combine jQuery with our own module from the Extension example
define(['jquery', 'TYPO3/CMS/FooBar/MyMagicModule'], function($, MyMagicModule) {
// $ is our jQuery object
// MyMagicModule is the object, which is returned from our own module
if(MyMagicModule.foo == 'bar'){
MyMagicModule.init();
}
});