magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Magento 2.4.4 - Static content deploy - Deprecated Error - null value #35293

Closed mkuzPL closed 2 years ago

mkuzPL commented 2 years ago

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?

m2-assistant[bot] commented 2 years ago

Hi @mkuzPL. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

themew commented 2 years ago

After composer require mageplaza/magento-2-polish-language-pack:dev-master mageplaza/module-smtp

Enter php bin/magento setup:upgrade

Then php bin/magento setup:static-content:deploy (-f if required)

Finally php bin/magento cache:clean

I also noticed you're also installing the mageplaza/module-smtp which is a great addon, however I don't think it works in php 8.1 yet.

Hanhan1989 commented 2 years ago

I had the same problem and I don't know why. I think this is a bug of Magento

Hanhan1989 commented 2 years ago

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_

FadedOut commented 2 years ago

@Hanhan1989 Hey, could you explain a bit more of what you mean by this? Where is the logo.png prior to you moving it? I'm running into the same deployment issue with a theme I'm using - if I remove the theme deployment works.

I'm wondering what needs to be changed with the theme to make it work? Or as you point out, moving the logo.png file?

Hanhan1989 commented 2 years ago

@FadedOut This problem appears to me due to the lack of the logo.png file in my custom theme.

├── [your theme]
       ├── registration.php
       ├── theme.xml
       └── web
                └── images
                 └── logo.png

Check if you are in the same situation.

FadedOut commented 2 years ago

@Hanhan1989 Thank you for the response :)

But hmm, well my theme is kind of an umbrella theme - it houses many sub-styles. The sub styles had the web>images folder but had an SVG in it. I tried dropping in a PNG to a substyle that I would target in the command. This still turned up the same error.

So I trial & error'd some more, thinking maybe if I added my own "web>images" folder because it did not exist (above the sub-styles - where registration.php is). I did that and added my logo.png file. I now receive the following error when running the deployment command (and it seems at the end of executing setup:upgrade as well) :

Error happened during deploy process: Warning: Trying to access array offset on value of type null in /home/cmp/public_html/vendor/magento/framework/View/Design/Theme/ThemeList.php on line 254

This line is like this: 'preview_image' => $media['preview_image'] ? $media['preview_image'] : null,

But I don't know what that could mean now...

Odd, very odd. I'm asking my theme dev to check it out but they aren't really sure either - thinking it's a Magento issue and I'm not sure it is. Ugh downtime is no good :(

mkuzPL commented 2 years ago

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 :)

dragonfly4 commented 2 years ago

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 can confirm this solves the problem. Child themes need to have a logo.png file

0m3r commented 2 years ago

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
                    ];
                }
faisal-project commented 2 years ago

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_

It's worked!

diogocolete commented 2 years ago

@0m3r

module magento-newsletter load file error. changing null to '' worked

ThisIsRuddy commented 2 years ago

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()));
ioweb-gr commented 2 years ago

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_

This was also the case for me. Missing the logo.png file in a child theme however. I wonder why it doesn't fetch it from the parent. How did you manage to detect the offending file if I may ask?

MartinVanVan commented 1 year ago

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.