exifr icon indicating copy to clipboard operation
exifr copied to clipboard

how to work with react-native

Open nschild opened this issue 3 years ago • 3 comments

Hi, I'm trying to get this working with react native, metro bundle, typescript, bable

import exifr from 'exifr'; gives me the error

Error: TransformError node_modules/exifr/dist/full.umd.js: node_modules/exifr/dist/full.umd.js:Invalid call at line 1: import(
/* webpackIgnore: true */
e)]

import Exif from '/node_modules/exifr/dist/lite.legacy.umd'; gives me the error

TypeError: Cannot read property 'includes' of undefined, js engine: hermes

What is the proper method to import this? Is there a bable config I need to add to support the webpack ignore statement?

nschild avatar Jul 16 '21 18:07 nschild

I get same issue

hungdev avatar Nov 10 '21 17:11 hungdev

As of my understanding, you need to use ES Modules with react-native, like so

import exifr from 'exifr/dist/full.esm.mjs'

And on metro.config

const defaultAssetExts = require("metro-config/src/defaults/defaults").assetExts;
module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
  resolver: {
    assetExts: [
        ...defaultAssetExts, // <- array spreading defaults
        'mjs'
    ]
  }
};

So it can include the mjs files this way. Only issue is that the import actually just imports a number

console.log('exifr', exifr);
console.log('typeof exifr', typeof exifr);

Gives

exifr 3
typeof exifr number

Any help?

pedro-pinho avatar Feb 01 '22 13:02 pedro-pinho

I changed to the lib, you can try it. https://github.com/mattiasw/ExifReader#using-react-native

hungdev avatar Feb 01 '22 14:02 hungdev