首页 > 解决方案 > NSString 类型的 JSON 值无法转换为 ABI38_0_0YGValue

问题描述

几个小时前,我的 expo/React Native 应用程序在本地运行得非常好。但是,为了部署应用程序,我不得不删除整个 node_modules 文件夹并运行 npm install 来恢复它。expo start --ios从那时起,当我在 IOS 上运行时,我遇到了这个可怕的错误。

在此处输入图像描述

出于某种原因,我的应用程序无法再读取“em”样式值。关于会发生什么的任何想法?这是我的配置::

包.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "0.1.10",
    "@react-navigation/bottom-tabs": "^5.8.0",
    "@react-navigation/compat": "^5.2.5",
    "@react-navigation/native": "^5.7.3",
    "@react-navigation/stack": "^5.9.0",
    "dotenv": "^8.2.0",
    "expo": "~38.0.8",
    "expo-image-picker": "^8.4.0",
    "expo-status-bar": "^1.0.2",
    "modal-react-native-web": "^0.2.0",
    "moment": "^2.27.0",
    "native-base": "^2.13.14",
    "react": "~16.11.0",
    "react-dom": "~16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-elements": "^2.3.0",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-google-books": "^1.0.4",
    "react-native-keyboard-aware-scroll-view": "^0.9.2",
    "react-native-loading-spinner-overlay": "^1.1.0",
    "react-native-screens": "^2.10.1",
    "react-native-star-rating": "^1.1.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "~8.1.0"
  },
  "private": true
}

应用程序.json

{
  "expo": {
    "name": "bindersmobile",
    "slug": "bindersmobile",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "white"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
}

标签: androidiosreact-nativeexpo

解决方案


如果您在 react native 中使用 android 的功能并在 ios 中运行 expo,则会发生该问题。这就是发生在我身上的事情。我设置了样式组件:

const SafeArea = styled(SafeAreaView)`
  flex: 1;
  margin-top:${StatusBar.currentHeight}
`;

由于“StatusBar.currentHeight”是android功能,我在ios中遇到了这个错误。在 IOS 中“StatusBar.currentHeight”没有返回有效值

我将代码转换为:

const SafeArea = styled(SafeAreaView)`
  flex: 1;
  ${StatusBar.currentHeight && `margin-top:${StatusBar.currentHeight}px`};
`;

此代码告诉,如果“StatusBar.currentHeight”有值,则应用 margin-top。


推荐阅读