无法导入 npm 安装的包 expo react native



我是反应原生的初学者。我在世博会上创建了一个示例应用程序。但是我无法导入 npm 安装的软件包来编码它显示 500 错误,例如

从"反应本机设备信息"导入设备信息;

它显示一个错误,例如"无法从屏幕\主屏幕解析反应本机设备信息.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
}

似乎该'react-native-device-info'使用本机代码(它需要根据 GitHub 存储库进行链接),因此如果不先分离/弹出您的 Expo 项目,就无法与 Expo 一起使用。

从查看您的 package.json 来看,您似乎还没有弹出。如果您确实需要使用此特定的设备信息库,则可以考虑弹出您的世博会项目。

如果正确设置此包,只需尝试重新加载包管理器服务器即可。

最新更新