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

Jimp not working on React Native #1191

Closed
Njinou opened this issue Feb 7, 2023 · 10 comments
Closed

Jimp not working on React Native #1191

Njinou opened this issue Feb 7, 2023 · 10 comments
Labels
bug there is a bug in the way jimp behaves duplicate

Comments

@Njinou
Copy link

Njinou commented Feb 7, 2023

Expected Behavior

I expect the library to work properly and the image to be shrink in size for a better User Experience.

Current Behavior

It crashes with this error: [TypeError: _$$_REQUIRE(dependencyMap[9], "jimp").read is not a function. (In '$$_REQUIRE(dependencyMap[9], "jimp").read('https://media.geeksforgeeks.org/wp-content/uploads/20190328185307/gfg28.png')', '$$_REQUIRE(_dependencyMap[9], "jimp").read' is undefined)]

Failure Information (for bugs)

Steps to Reproduce

yarn add Jimp on react-native vanilla
//import Jimp from "jimp";
Or
var Jimp = require("jimp");

try{
Jimp.read
('https://media.geeksforgeeks.org/wp-content/uploads/20190328185307/gfg28.png').then (image => console.log("Images",image))
.catch(e => console.log("first casth ",e))
}
catch(e){
console.log("this is the error ",e);
}

Screenshots

Context

  • Jimp Version:
  • Operating System:
  • Node version:
    Uploading Screen Shot 2023-02-07 at 2.55.31 AM.png…Screen Shot 2023-02-07 at 3 01 07 AM## Failure Logs
@marvinruder
Copy link

I am not too familiar with React Native, but its Javascript engine might require the browser version of Jimp. This is how I got it running in (classic) React:

await import("jimp/browser/lib/jimp.js"); // This statement loads the browser version of Jimp and makes it available as the global variable `window.Jimp`.
const { Jimp } = window as typeof window & { Jimp: any }; // any can probably be replaced with something else from the Jimp package

@marvinruder
Copy link

marvinruder commented Feb 7, 2023

Issue also reproducable in Node, see marvinruder/jimp-no-types-available.

(Browser version might still help for the moment.)

@marvinruder
Copy link

@Njinou Can you share your Typescript configuration with us? I was able to reproduce the issue in a setup with allowSyntheticDefaultImports set to true, but without esModuleInterop. After replacing allowSyntheticDefaultImports with esModuleInterop, Jimp works fine for me.

@Njinou
Copy link
Author

Njinou commented Feb 7, 2023 via email

@marvinruder
Copy link

marvinruder commented Feb 7, 2023

Okay, I tried reproducing the issue in plain Javascript, but was unsuccessful so far. Perhaps you can provide a small repository setup which reproduces the issue?

Edit: nevermind, I am able to reproduce it using classic React and plain Javascript.

@marvinruder
Copy link

@hipstersmoothie Can you have a look at my MWE repo marvinruder/jimp-react?

It appears that over the years many issues were found when attempting to use Jimp in frontend tools like React (Native) (see this one and also #1091, #761), so maybe we can use a setup like mine to find and fix them one by one? Perhaps the more general goal of getting Jimp running in frontend tools should be tracked in a separate issue? Let me know what you think!

@hipstersmoothie
Copy link
Collaborator

Yeah let's do that!

I just invited you to the org. Maybe you could transfer the repo there and we could use it to test issues like this in the future.

I think that you should created another issue that tracks this like you said and merge all of these other issues into it

@hipstersmoothie
Copy link
Collaborator

Once you access the invite I'll also give you triage access to this repo

@marvinruder marvinruder mentioned this issue Feb 7, 2023
3 tasks
@marvinruder marvinruder added duplicate bug there is a bug in the way jimp behaves labels Feb 7, 2023
@marvinruder
Copy link

Thanks for reporting this bug, @Njinou! We are currently investigating several issues with Jimp in frontend tools such as React [Native], and will consolidate the discussion there. We will therefore close this issue as duplicate, but continue to work on a fix. You can follow the progress on that in #1194.

@marvinruder marvinruder closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2023
@Njinou
Copy link
Author

Njinou commented Feb 7, 2023

@marvinruder Please let me know if I can be of any help to speed up the fix
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug there is a bug in the way jimp behaves duplicate
Projects
None yet
Development

No branches or pull requests

3 participants