Laravel-Backpack / download-operation

MIT License
11 stars 5 forks source link

Dependency Version Conflict with backpack/download-operation #8

Closed adrinro closed 1 month ago

adrinro commented 1 month ago

Hello,

I am encountering a version conflict issue when trying to install backpack/download-operation in my Laravel project. My project's composer.json includes dependencies that seem to be incompatible with the versions required by backpack/download-operation.

Here are the relevant parts of my composer.json:

"require": {
    "php": "^8.2",
    "backpack/crud": "^6.7",
    "backpack/pro": "^2.2",
    "backpack/theme-coreuiv4": "^1.1",
    "laravel/framework": "^11.0",
    "laravel/tinker": "^2.9",
    "mcamara/laravel-localization": "^2.0",
    "spatie/browsershot": "*",
    "spatie/laravel-translatable": "^6.7"
}

The issues are as follows:

  1. backpack/download-operation versions 1.0.0 to 1.0.1 require backpack/crud ^4.1.0, but my project uses backpack/crud ^6.7, which is incompatible.
  2. Versions 2.0.0 to 2.1.0 of backpack/download-operation require backpack/crud ^5.0, which is also incompatible with my version of backpack/crud ^6.7.
  3. Version 2.2.0 of backpack/download-operation requires spatie/browsershot ^3.41, but my project specifies spatie/browsershot as * , intending to use a version compatible with spatie/browsershot ^4.1.

Given these conflicts, I am unable to install a compatible version of backpack/download-operation that works with the current versions of backpack/crud and spatie/browsershot in my project.

Could you please advise on how to resolve this issue or if there are plans to update backpack/download-operation to be compatible with newer versions of these dependencies?

Thank you for your assistance.

pxpm commented 1 month ago

Hello @adrinro

Like you found out, this operation is not compatible with the newer spatie/browsershot version.

I haven't tested the new version so I am not sure about the possible breaking changes or if there is any that impact our code.

From spatie/browsershot upgrade guide there does not seem to be any major breaking change that would impact us.

I've created a branch that allow browsershot v4+ to be installed but I haven't got time to properly test this.

If you want to give it a try, you can change your composer.json and add to require:

"backpack/download-operation":"dev-update-browsershot as 2.3"

Please let me know if it works for you 🙏

Cheers

adrinro commented 1 month ago

Hello,

I've followed the installation instructions provided and successfully installed backpack/download-operation along with its necessary dependencies. However, I've encountered an issue when using Browsershot within the downloadFile() function of the package.

Even though I've correctly specified the paths for node and npm in my test file (and it works without issues), attempting to do the same within the downloadFile() function of the package results in an error indicating that the "node" command is not recognized. Interestingly, despite this error, I can see that Browsershot has successfully generated the screenshot in HTML format in the system's temp folder. However, it seems that due to the error, it fails to convert this HTML into PDF.

I want to mention that with this setup, the previous error related to installation by dependencies no longer occurs, which is a positive development. Nonetheless, due to the mentioned issue with Browsershot, I've been unable to verify the functionality 100% in my environment to ensure everything works as expected.

Could you provide any guidance on how to resolve the issue with Browsershot not recognizing the "node" command when executed within the downloadFile() function? Additionally, it would be greatly beneficial if there was a way to specify the paths for node and npm, possibly through an environment variable in the .env file, to make this configuration more flexible and easier to manage across different environments.

Here an example of the function downloadFile() that I modify:

    protected function downloadFile($data)
    {
        return response()->streamDownload(function () use ($data) {
            echo Browsershot::html(view($data['view'], $data))
                ->setNodeBinary('C:\\Program Files\\nodejs\\node')
                ->setNpmBinary('C:\\Program Files\\nodejs\\npm')
                ->format($data['format'])
                ->pdf();
        }, $data['filename'], $data['headers']);
    }

And here is the test file I created to check that browsershot is working or not:

<?php
require 'vendor/autoload.php';
use Spatie\Browsershot\Browsershot;

Browsershot::url('https://www.google.com')
    ->setNodeBinary('C:\\Program Files\\nodejs\\node')
    ->setNpmBinary('C:\\Program Files\\nodejs\\npm')
    ->save('google.png');

I'm sorry I can't be of more help with this problem, thank you for your quick response.

Thank you in advance.

pxpm commented 1 month ago

Hey @adrinro

thanks for the input, it was very helpful 👍 .

I did some tests myself, and probably my setup is different than yours, so I needed to set different options on the Browsershot instance.

I think you were right by making it easy to configure the browsershot instance without having to overwrite the whole function. Plus it wouldn't had a default that worked for all your cruds, so you manually had to change every crud you wanted to use the operation. No bueno I'd say, nice catch 👍

In that regard I added a config file to download-operation, and an option for you to specify your own Browsershot configs, you can check the docs on that branch readme too.

For me, on my setup, the configuration that works is:

Browsershot::html(view($data['view'], $data))
                ->noSandbox()
                ->setChromePath('/usr/bin/google-chrome-stable')
                ->format($data['format'])
                ->pdf();

image

That's the default view .. doesn't look great tho 😞 but it's a starting point, most of the times you want it to be realy pretty, so pretty custom.

Let me know if that helps.

Cheers

pxpm commented 1 month ago

We have tagged v2.2.1 with support for browsershot ^4.0.

Thanks for the heads up @adrinro , I hope you were able to fix your setup so that the package works as expected. 🙏

Please read the new readme section about how to configure the Browsershot instance.

If you still experiencing issues related with this package, please open a new issue 🙏

Cheers