1
votes

I’m a beginner in react native. I created a sample app with the expo. But I can’t import npm installed packages to code its shows an 500 error like

import DeviceInfo from ‘react-native-device-info’;

it shows an error like “unable to resolve react-native-device-info from screens\homescreen.js”

 HomeScreen.js
 ==========
 import React from 'react';
    import {
      Image,
      Platform,
      ScrollView,
      StyleSheet,
      Text,
      TouchableOpacity,
      View,
      StatusBar,
      Dimensions,
      LayoutAnimation,
      Alert,
      Linking,
    } from 'react-native';
    import { WebBrowser } from 'expo';
    import { BarCodeScanner, Permissions } from 'expo';
    import { MonoText } from '../components/StyledText';
    import DeviceInfo   from 'react-native-device-info';
    ...
    ...

Package.json
==========
{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "node ./node_modules/jest/bin/jest.js --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/samples": "2.1.1",
    "expo": "^31.0.2",
    "link": "^0.1.5",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
    "react-native-camera": "^1.4.3",
    "react-native-device-info": "^0.24.3",
    "react-native-permissions": "^1.1.1",
    "react-native-qrcode-scanner": "^1.1.0",
    "react-navigation": "^2.18.2"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.0.0",
    "jest-expo": "^31.0.0"
  },
  "private": true
}
2
this que might be helpful to you . stackoverflow.com/questions/47737609/…Asmi

2 Answers

1
votes

It seems that that 'react-native-device-info' uses native code (it requires linking as per the GitHub Repo) and therefore can't be used with Expo without detaching / ejecting your Expo project first.

From looking at your package.json, it seems that you haven't ejected yet. If you really need to use this specific device info library, you can look into ejecting your Expo project.

0
votes

If you setup this package properly, just try to reload package-manager-server.