callstack / react-native-image-editor

A library providing an API for cropping images from the web and the local file system.
MIT License
376 stars 118 forks source link

TypeError: null is not an object (evaluating 'RNCImageEditor.cropImage')] #38

Closed Wayne-II closed 4 years ago

Wayne-II commented 4 years ago

Question

I'm running into an issue that I cannot solve. I can't find any examples of using a local file - advanced usage example uses http - but I don't know that that's the issue. The local file URI I'm getting is from React Native Expo Camera.

One thing I noticed is the URI seems to be double URI encoded. Running decodeURI doesn't solve this. So I've had to hard code the expo cache. The two characters that are URI encoded are: %2540 - @ %252F - / These chraceters are on either side of anonymous in the Expo Camera cache directory.

The end result is a file URI that looks like: file:///data/data/host.exp.exponent/cache/ExperienceData/@anonymous/expo-template-bare-23a82ea2-a903-4519-a43f-fa02cdb99fc8/Camera/489808c7-2b8a-47af-b48c-6d86644c0a87.jpg

The crop data is something similar to the following - depends on the image. { "displaySize": Object { "height": 596.2993774414062, "width": 271.7322692871094, }, "offset": Object { "x": 180.36246299743652, "y": 648.2353515625, }, "resizeMode": "cointain", "size": Object { "height": 596.2993774414062, "width": 271.7322692871094, }, } My issue is that I'm getting a promise rejection error - I think it's actually a TypeError.

[Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNCImageEditor.cropImage')]

  • node_modules/@react-native-community/image-editor/lib/ImageEditor.js:65:26 in cropImage
  • App.js:180:27 in handleCrop
  • App.js:197:6 in _callee3$
  • node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  • node_modules/regenerator-runtime/runtime.js:271:30 in invoke
  • node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  • node_modules/regenerator-runtime/runtime.js:135:28 in invoke
  • node_modules/regenerator-runtime/runtime.js:145:19 in
  • node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  • node_modules/promise/setimmediate/core.js:123:25 in
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:152:14 in _callTimer
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:200:17 in _callImmediatesPass
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:473:30 in callImmediates
  • [native code]:null in callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:337:6 in __callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6 in
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:10 in __guard
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:17 in flushedQueue
  • [native code]:null in flushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue

I modified https://github.com/react-native-community/react-native-image-editor/blob/master/lib/ImageEditor.js#L63 to match the following: static cropImage(uri: string, cropData: ImageCropData): Promise<string> { console.log( 'Calling RNC Image Editor', uri, cropData ) return RNCImageEditor.cropImage(uri, cropData); } I used this modification to get the above URI and cropData code.

I don't know what I'm doing wrong.

Here is my system information. In addition I'm using sublime text as my editor. I'm not using xcode.

Expo CLI 3.1.2 environment info: System: OS: macOS High Sierra 10.13.1 Shell: 3.2.57 - /bin/bash Binaries: Node: 8.11.4 - /usr/local/bin/node npm: 6.11.3 - /usr/local/bin/npm IDEs: Xcode: 9.2/9C40b - /usr/bin/xcodebuild npmPackages: expo: ^35.0.0 => 35.0.0 react: 16.8.3 => 16.8.3 react-native: ^0.59.8 => 0.59.10 npmGlobalPackages: expo-cli: 3.1.2

EricLewe commented 4 years ago

My suggestion might not be related to your case since I am on RN 0.59.5. (NPM version of @react-native-community/image-editor is 2.0.0) and use images from url.

In my case I forgot to link the library. Running the following command, solved my issue: react-native link @react-native-community/image-editor

Wayne-II commented 4 years ago

I failed to mention that. I had linked the library. Thinking I had to link RNCImageEditor and not @react-native-community/image-editor, I unlinked the library. Finding that I had properly linked the library the first time I had linked the library once again, to no avail.

Wayne-II commented 4 years ago

Having an epiphany, I Googled around and found this:

But no native modules... The most limiting thing about managed Expo projects is that you can't add in your own native modules without detaching and using ExpoKit. Continue reading the next question for a full explanation. https://docs.expo.io/versions/latest/introduction/faq/#what-is-the-difference-between-expo-and

Wayne-II commented 4 years ago

Prematurely closed this. Further reading the docs made me think maybe Expo had a ImageEditor/cropping module I could use without ejecting.

https://docs.expo.io/versions/latest/sdk/imagemanipulator/

Temirtator commented 4 years ago

this bug is not fixed, yet

mabecth commented 4 years ago

Any idea of how to fix this?

ola-wale commented 4 years ago

running npx pod-install fixed this for me.