bamlab / react-native-image-resizer

🗻 Resize local images with React Native
MIT License
1.6k stars 341 forks source link

Cannot read property of createResizedImage of undefined :( #234

Closed ORESoftware closed 4 years ago

ORESoftware commented 4 years ago

There is no "main" property in package.json:

{
  "name": "react-native-image-resizer",
  "version": "1.2.1",
  "description": "Rescale local images with React Native",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/bamlab/react-native-image-resizer.git"
  },
  "keywords": [
    "react-native",
    "react",
    "android",
    "ios",
    "images",
    "image",
    "image-resizer",
    "scaling",
    "scale",
    "resize"
  ],
  "peerDependencies": {
    "react": "^15.4.0 || ^16.0.0-alpha",
    "react-native": ">=v0.40.0"
  },
  "author": "Florian Rival <florianr@bam.tech> (http://bam.tech)",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/bamlab/react-native-image-resizer/issues"
  },
  "homepage": "https://github.com/bamlab/react-native-image-resizer#readme",
  "devDependencies": {
    "cz-conventional-changelog": "^1.2.0"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

and I am getting:

Screen Shot 2020-05-06 at 2 21 35 PM

and the code is just:

import ImageResizer from 'react-native-image-resizer';

 ImageResizer.createResizedImage(
            imageUri,
            newWidth,
            newHeight,
            'JPEG',
            1
        ).then((response) => {
            console.log('successfully resized image:', response);
            return getLocalImageBase64(response.uri);
        });

everything compiles with typescript tho! :(

there is no index.js file in the project:

Screen Shot 2020-05-06 at 2 22 45 PM
superbelko1 commented 4 years ago

oh same problem trying to resolve(

ORESoftware commented 4 years ago

I think it's b/c the project is missing an index.js file

PierreCapo commented 4 years ago

@ORESoftware @superbelko1 I have just published a new version (1.2.2) with an index.js file and a main key in the package.json. Can you try it out and tell me if that fixes your problem ?

Thanks in advance.

ORESoftware commented 4 years ago

Yeah I don't think it worked, I logged "RAAZZZOOOOM":

Screen Shot 2020-05-07 at 12 19 00 PM

and I still get that error:

Screen Shot 2020-05-07 at 12 20 37 PM

I am not sure why :(

ORESoftware commented 4 years ago

ok so it's not because of index.js, it's because NativeModules from react-native doesn't have the export...

if we run:

import { NativeModules, Platform } from 'react-native';
 console.log(Object.keys(NativeModules));

I get:

  "AppState",
  "DevSettings",
  "DevLoadingView",
  "StatusBarManager",
  "LinkingManager",
  "ExponentNotifications",
  "ExponentUpdates",
  "ExceptionsManager",
  "NativeUnimoduleProxy",
  "UMReactNativeEventEmitter",
  "AsyncLocalStorage",
  "AIRGoogleMapManager",
  "AIRGoogleMapMarkerManager",
  "AIRMapManager",
  "AIRMapMarkerManager",
  "LottieAnimationView",
  "ExponentAR",
  "ExpoNativeModuleIntrospection",
  "ExponentSplashScreen",
  "ExponentTest",
  "RNCViewPager",
  "ReanimatedModule",
  "RNAWSCognito",
  "RNCAppearance",
  "RNCNetInfo",
  "RNCSafeAreaView",
  "RNCWebViewManager",
  "RNGestureHandlerModule",
  "RNSharedElementTransition",
  "RNSVGRenderableManager",
  "RNSVGCircleManager",
  "RNSVGEllipseManager",
  "RNSVGGroupManager",
  "RNSVGForeignObjectManager",
  "RNSVGImageManager",
  "RNSVGLineManager",
  "RNSVGMarkerManager",
  "RNSVGMaskManager",
  "RNSVGPathManager",
  "RNSVGPatternManager",
  "RNSVGRectManager",
  "RNSVGSvgViewManager",
  "RNSVGTextManager",
  "RNSVGTextPathManager",
  "RNSVGTSpanManager",
  "RNSVGUseManager",
  "RNViewShot",
  "AccessibilityManager",
  "AlertManager",
  "Clipboard",
  "DeviceInfo",
  "I18nManager",
  "KeyboardObserver",
  "ModalManager",
  "RedBox",
  "ScrollViewManager",
  "SourceCode",
  "Timing",
  "TVNavigationEventEmitter",
  "UIManager",
  "WebSocketModule",
  "ImageEditingManager",
  "ImageStoreManager",
  "PlatformConstants",
  "ActionSheetManager",
  "NativeAnimatedModule",
  "BlobModule",
  "FileReaderModule",
  "ImageViewManager",
  "NetInfo",
  "Networking",
  "SettingsManager",
  "Vibration",
ORESoftware commented 4 years ago

So perhaps the module is not linked properly. I am in an expo project and the install instructions say:

yarn add react-native-image-resizer
cd ios && pod install

but I don't have a folder called "ios" in my project

PierreCapo commented 4 years ago

I'm not sure they have added a way to add custom native modules on expo. You need to use what they provide or eject.