Using TYPO3 12.
I’m trying to add a JavaScript module to my backend module but I can’t get it working.
Here is what I’ve done by following the official documentation on this:
- Register JS module in
/Configuration/JavaScriptModules.php
return [
'dependencies' => ['backend'],
'imports' => [
'@vendor/package/' => 'EXT:vendor/Resources/Public/JavaScript/',
],
];
- Providing
PageRenderer
to the module controller via/Configuration/Services.yaml
VendeorpackageControllerBackendBackendModuleController:
tags: ['backend.controller']
arguments:
$pageRenderer: '@TYPO3CMSCorePagePageRenderer'
- Using
loadJavaScriptModule
to add the JS module to the page
public function initializeAction(): void
{
$this->pageRenderer->loadJavaScriptModule('@vendor/package/backend-module.js');
}
I already tried alternatives like accessing the JavaScriptRenderer
directly via the PageRenderer
or using the f:be.pageRenderer
ViewHelper but nothing seems to work.
I could also verify by debugging that the JS file gets added to the JavaScriptRenderer
and is inside its importMap
. I’ve also checked all file paths for possible typos multiple times now.
What am I missing here?