【问题标题】:JSON value of type NSString cannot be converted to a ABI38_0_0YGValueNSString 类型的 JSON 值无法转换为 ABI38_0_0YGValue
【发布时间】:2020-08-28 15:43:12
【问题描述】:

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

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

package.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
}

app.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"
    }
  }
}

【问题讨论】:

  • 它可以来自任何与 expo SDK 不兼容的最新包。你能通过expo install packageName再次安装包吗?此命令将安装兼容包
  • 所以我需要为 package.json 中的每个包运行这个命令?
  • 也许可以,但您可以先测试那些您认为会造成问题的软件包。
  • 问题是,在我删除nodes_module之前,所有的包都在工作。因此,我假设 package.json 中的所有版本都是正确的...
  • 你也可以check out到具体的commit来测试哪个commit有这个问题

标签: android ios react-native expo


【解决方案1】:

如果您在 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。

【讨论】:

    【解决方案2】:

    我在我的 react native 项目中遇到了这个确切的错误。最后发现这是因为我的样式中有一个字符串(宽度:'8'),我应该有一个数字(宽度:8)。

    【讨论】:

      【解决方案3】:

      之前

      这些代码给出了错误“NSString 类型的 JSON 值无法转换为 ABI38_0_0YGValue”

      const TextInput = styled.TextInput.attrs(props => ({
          type: "text",
          mt: props.mt,
          mb: props.mb,
          radius: props.radius,
      }))`
          width: 100%;
          background-color: #f7f7f7;
          border-width: 0px;
          border-radius: ${props => props.radius};
          font-size: 20px;
          padding-horizontal: 20px;
          padding-vertical: 14px;
          margin-top: ${props => props.mt};
          margin-bottom: ${props => props.mb};
      
      `;
      

      之后

      我必须为 props.mt、props.mb 和 props.radius 设置默认值,以防没有任何值传递给它们。

      const TextInput = styled.TextInput.attrs(props => ({
          type: "text",
          mt: props.mt || '0px',
          mb: props.mb || '0px',
          radius: props.radius '0px',
      }))`
      

      【讨论】:

        猜你喜欢
        • 2017-04-10
        • 1970-01-01
        • 2019-05-02
        • 1970-01-01
        • 2017-04-11
        • 1970-01-01
        • 2019-02-03
        • 2019-01-10
        • 2016-06-06
        相关资源
        最近更新 更多