#108874JavaScriptRenderer throws unclear TypeError when module cannot be resolved
Description
When `ImportMap::resolveImport()` returns `null` for a JavaScript module (e.g. module not in import map or misconfigured), `JavaScriptRenderer::render()` fails with a generic PHP TypeError:
TypeError: TYPO3\CMS\Core\Page\JavaScriptRenderer::{closure}(): Argument #1 ($url) must be of type string, null given
in vendor/typo3/cms-core/Classes/Page/JavaScriptRenderer.php line 137
The closure used in `array_map()` is typed as `fn(string $url)` but receives `null` from the `$modules` array. The error does not indicate which module failed to resolve, making debugging difficult.
*Root cause*
- `$modules` is built from `$this->importMap->resolveImport($instruction->getName())` which returns `?string`.
- When a module cannot be resolved, `resolveImport()` returns `null`.
- The code then passes `$modules` (values only) to `array_map()`, so the failing module name is never available in the error.
**Expected behavior**
When a module cannot be resolved, the code should throw a clear exception that includes the module name (e.g. `@my/extension/SomeModule`), so developers can fix the missing or wrong import configuration.
**Proposed solution**
- Replace the `array_map()` over `$modules` with a `foreach ($modules as $moduleName => $url)`.
- Before creating each script tag, validate that `$url` is a non-empty string.
- If not, throw a `\RuntimeException` with a message like:
`JavaScript module “%s” could not be resolved (import map returned no src URL).`
Reviews 3
History 27
-
Gerrit Code Review pushed patch set 1 for main to change 92687 status
NewUnder Review 02/05/26, 15:15 -
Gerrit Code Review pushed patch set 1 for main to change 92698 02/06/26, 05:40
-
Gerrit Code Review pushed patch set 2 for main to change 92698 02/06/26, 06:10
-
Gerrit Code Review pushed patch set 3 for main to change 92698 02/06/26, 07:34
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 92718 02/06/26, 14:38
-
Himanshu Ramavat commented and changed status
Under ReviewResolved done0 %100 % 02/06/26, 15:00 -
Benni Mack changed status
ResolvedClosed 03/31/26, 08:10
Applied in changeset commit:886a2ba5d0197f9ec2085037d437d62740e4d789.