magento2: Magento 2.4.4 - Static content deploy - Deprecated Error - null value

I’ve made fresh install of Magento 2.4.4 PHP version is 8.1.4

I’ve created two child themes (one of luma & one of blank) I’ve installed PL language pack using command: composer require mageplaza/magento-2-polish-language-pack:dev-master mageplaza/module-smtp

Next step (after installing language pack) should be: php bin/magento setup:static-content:deploy pl_PL -f

Following command causes an error: Error happened during deploy process: Deprecated Functionality: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /workspaces/magento-demo/vendor/magento/framework/View/Asset/PreProcessor/FileNameResolver.php on line 44 image

Line 44 of FileNameResolver.php looks like this: image

I’ve found somethinf like this: [PHP 8.1: Passing null to non-nullable internal function parameters is deprecated]

How can I fix this error?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I found the origin of the problem. The problem was we should put the logo.png image file in our theme: app/design/frontend/[our_vendor]/[theme]/web/images/logo.png

Quick fix in file: magento/module-deploy/Collector/Collector.php

Change line 95 from: if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule())) { to: if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule()) || is_null($file->getFileName())) {

Patch here for you:

index b09001a..686c4de 100644
--- a/vendor/magento/module-deploy/Collector/Collector.php
+++ b/vendor/magento/module-deploy/Collector/Collector.php
@@ -3,6 +3,7 @@
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
+
 namespace Magento\Deploy\Collector;

 use Magento\Deploy\Source\SourcePool;
@@ -69,11 +70,12 @@ class Collector implements CollectorInterface
      * @param Manager|null $moduleManager
      */
     public function __construct(
-        SourcePool $sourcePool,
+        SourcePool       $sourcePool,
         FileNameResolver $fileNameResolver,
-        PackageFactory $packageFactory,
-        Manager $moduleManager = null
-    ) {
+        PackageFactory   $packageFactory,
+        Manager          $moduleManager = null
+    )
+    {
         $this->sourcePool = $sourcePool;
         $this->fileNameResolver = $fileNameResolver;
         $this->packageFactory = $packageFactory;
@@ -90,7 +92,7 @@ class Collector implements CollectorInterface
         foreach ($this->sourcePool->getAll() as $source) {
             $files = $source->get();
             foreach ($files as $file) {
-                if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule())) {
+                if ($file->getModule() && !$this->moduleManager->isEnabled($file->getModule()) || is_null($file->getFileName())) {
                     continue;
                 }
                 $file->setDeployedFileName($this->fileNameResolver->resolve($file->getFileName()));

I have the same compilation error with the ‘empty’ (virtual) theme

https://github.com/magento/magento2/blob/2.4.4/app/code/Magento/Deploy/Collector/Collector.php#L96

$file->setDeployedFileName($this->fileNameResolver->resolve($file->getFileName()));

$file->getFileName() is null

https://github.com/magento/magento2/blob/2.4.4/app/code/Magento/Deploy/Source/Themes.php#L52-L63

foreach ($this->filesUtil->getStaticPreProcessingFiles() as $info) {
            list($area, $theme, $locale, $module, $fileName, $fullPath) = $info;
            if (!empty($theme)) {
                $locale = $locale ?: null;
                $params = [
                    'area' => $area,
                    'theme' => $theme,
                    'locale' => $locale,
                    'module' => $module,
                    'fileName' => $fileName,
                    'sourcePath' => $fullPath
                ];
                $files[] = $this->packageFileFactory->create($params);
            }
        }

because in accumulateThemeStaticFiles system add nulled filename if any static files weren’t found

https://github.com/magento/magento2/blob/2.4.4/lib/internal/Magento/Framework/App/Utility/Files.php#L955

if (!$files) {
                    $result[] = [
                        $themeArea,
                        $themePackage->getVendor() . '/' . $themePackage->getName(),
                        null,
                        null,
                        null,
                        null
                    ];
                }

I found the origin of the problem. The problem was we should put the logo.png image file in our theme: app/design/frontend/[our_vendor]/[theme]/web/images/logo.png

I had the same issue with my custom backend theme. I deleted an override on a css. So had a custom theme with no overrides. But funny thing is that it doesn’t matter which file you add to your custom theme. After i’ve added app/design/adminhtml/[our_vendor]/[theme]/web/test.txt it worked. setup:static-content:deploy did not brake. Apperently the magento/module-deploy/Collector/Collector.php need any file.

I found the origin of the problem. The problem was we should put the logo.png image file in our theme: app/design/frontend/[our_vendor]/[theme]/web/images/logo.png

Thank You! That worked for me, the problem is gone 😃