Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when executing Sharp constructor from React app running in Electron in WSL2 dev env, accessed via X11 #2640

Closed
james-braund opened this issue Mar 27, 2021 · 3 comments
Labels

Comments

@james-braund
Copy link

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?

Yes - 0.7.2

What are the steps to reproduce?

Prerequisites:

  • Host machine running Windows 10 Pro (10.0.19042)
  • Using Ubuntu/WSL2 (via VSCode) to run development environment
  • Building a React+Electron app (using electron-forge + Webpack + React)
  • sharp is installed and configured as an external in Webpack config
  • Using npm start in development, GUI is output to X11 window
  • VcXsrv is used to access the X11 window from the Windows host
  • In the React app, simple button invokes the following function:
export const testResize = async () => {
  const src = "/path/to/input.jpg";
  const dest = "/path/to/output.jpg";

  try {
    await sharp(src).resize(400, 600).toFile(dest);
  } catch (e) {
    console.error(`Error occured resizing image ${src}`, e);
  }
};

This results in the error:

Error: Input file has corrupt header: jpegload: parameter filename not set

Running the same function in a test file directly in the WSL2 shell (zsh) works fine, and an output file is produced. I am therefore confident that the input file is not a problem.

What is the expected behaviour?

Input file should be read correctly.

Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?

I don't think so. As you can see from the above prerequisites, it's quite complex. I have a hunch about it which I'll mention after completing the template.

Are you able to provide a sample image that helps explain the problem?

Not relevant - no image being produced, and the input image doesn't seem to relate to the issue.

What is the output of running npx envinfo --binaries --system?

npx: installed 1 in 1.183s

  System:
    OS: Linux 4.19 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz
    Memory: 20.31 GB / 25.02 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.0/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm

Supplementary info

Reviewing the docs, I came across the recommendation to ensure that the arch/platform when running npm install matches the runtime arch/platform. Unless I'm fundamentally missing something, I believe it does. I am not building an Electron binary for a Windows target (yet - so it will be relevant when I do), and the Node process that electron-forge is executing to run my app in development is running within the WSL2 container (i.e. on Ubuntu). I'm simply access the GUI via X11 from the Windows host machine. I can't logically think of a reason why this would impact the result, but I don't really have any other ideas.

I fully expect that this is something very specific to do with my setup, and not necessarily a bug within sharp - but I would be very grateful for any pointers you can offer.

Thanks!

@lovell
Copy link
Owner

lovell commented Mar 27, 2021

Hello, it's possible you've run into #2535 albeit presented as a different error due to the setup involved.

If so, there's a pre-release v0.28.0-beta1 that should fix this, please see #2604 (comment) if you think you might be able to help test it.

@james-braund
Copy link
Author

Hi @lovell - thanks for the speedy response! A quick test after updating to the v0.28.0-beta1 version suggest that this fixes my problem.

Would you like any other details capturing or recording anywhere as part of my testing?

@lovell
Copy link
Owner

lovell commented Mar 27, 2021

Great, thanks for checking/confirming, it's very likely this is the same problem as #2535 so please subscribe to it and/or #2604 for updates.

@lovell lovell closed this as completed Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@lovell @james-braund and others