Skip to content

Error : Use of undeclared identifier 'YGValue' when building iOS #33976

Description

@JB-CHAUVIN

Description

Hello,

I have the following error when building with the latest RN version.

I was just trying to upgrade...
iScreen Shoter - 2022-06-08 10:29:49 688

Error :  Use of undeclared identifier 'YGValue' when building iOS

Version

0.69-RC.6

Output of npx react-native info

System:
OS: macOS 12.2.1
CPU: (10) x64 Apple M1 Pro
Memory: 1.71 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.19.1 - /usr/local/bin/node
Yarn: 1.22.18 - /opt/homebrew/bin/yarn
npm: 6.14.16 - /usr/local/bin/npm
Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.0-rc.6 => 0.69.0-rc.6
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

I tried to upgrade...

Snack, code example, screenshot, or link to a repository

N/A

Activity

  1. mfik commented on Jun 11, 2022

    @mfik

    Same!

  2. mfik commented on Jun 11, 2022

    @mfik

    Related #33815

  3. fortmarek commented on Jun 13, 2022

    @fortmarek
    Contributor

    Hey @JB-CHAUVIN 👋

    Would it be possible to add a sample or reproduction steps? The current 0.69.0-rc.6 works when using a project created with the RN template.

  4. mfik commented on Jun 13, 2022

    @mfik

    The new error is for react-native-webview

    image

    Package:

    {
    "main": "index.js",
    "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "expo start --dev-client",
    "test": "jest"
    },
    "dependencies": {
    "@config-plugins/react-native-google-cast": "^2.0.0",
    "@expo-google-fonts/poppins": "^0.2.2",
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@react-navigation/drawer": "^6.4.1",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/native-stack": "^6.6.1",
    "@react-navigation/stack": "^6.2.1",
    "axios": "^0.21.1",
    "expo": "^45.0.5",
    "expo-app-loading": "~2.0.0",
    "expo-av": "~11.2.3",
    "expo-dev-client": "~1.0.0",
    "expo-font": "~10.1.0",
    "expo-image-loader": "~3.2.0",
    "expo-keep-awake": "~10.1.1",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "expo-updates": "~0.13.2",
    "moment": "^2.29.3",
    "react": "18.0.0",
    "react-dom": "17.0.2",
    "react-hook-form": "^6.15.5",
    "react-native": "0.69.0-rc.6",
    "react-native-gesture-handler": "~2.2.1",
    "react-native-google-cast": "^4.2.4",
    "react-native-reanimated": "~2.8.0",
    "react-native-safe-area-context": "4.2.4",
    "react-native-screens": "~3.11.1",
    "react-native-sound-player": "^0.12.0",
    "react-native-storage": "^1.0.1",
    "react-native-swift": "^1.2.3",
    "react-native-track-player": "^2.2.0-rc3",
    "react-native-web": "0.17.7",
    "react-native-webview": "^11.22.2",
    "react-player": "^2.10.0"
    },
    "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~17.0.21",
    "@types/react-dom": "~17.0.11",
    "@types/react-native": "~0.67.6",
    "babel-preset-expo": "~9.1.0",
    "jest-expo": "^45.0.0",
    "typescript": "~4.3.5"
    },
    "jest": {
    "preset": "react-native"
    },
    "private": true,
    "name": "None",
    "version": "1.0.0",
    "isSwift": true
    }

  5. mfik commented on Jun 13, 2022

    @mfik

    Placed the file in the folder to see if it would build. Even tho i don't have a case sensitive volume, the next error shows up. The file is in the folder:

    image

  6. mfik commented on Jun 15, 2022

    @mfik

    Also happening in an almost clean project. @JB-CHAUVIN Is this a priority issue? Haven't been able to build in since monday and i'm seeing a lot of related issues when i search. The error exists in Expo 43, 44 and 45 in multiple modules (safe-area-context, webview, Asynstorage).

    image

  7. renchap commented on Jun 21, 2022

    @renchap
    Contributor

    I am seeing the same error when updating my app to RN 0.69-rc6:

    /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.m:17:20: error: use of undeclared identifier 'YGValue'
      subview.width = (YGValue) { RCTScreenSize().width, YGUnitPoint };
    

    This seems to be different than #33648 as I dont have a case-sentitive FS (standard macOS APFS).

  8. karatekid430 commented on Jun 23, 2022

    @karatekid430

    Experiencing this with 0.69.0 release

  9. Bardiamist commented on Jun 23, 2022

    @Bardiamist
    Contributor

    Hmm, I too have this error after update to 0.69.0
    Nothing helped as clear pods/clean build
    But fresh project built successfully
    How to update my project, what can be?

    Output of npx react-native info
    System:
        OS: macOS 12.4
        CPU: (10) arm64 Apple M1 Max
        Memory: 28.07 GB / 64.00 GB
        Shell: 5.8.1 - /bin/zsh
      Binaries:
        Node: 18.4.0 - /opt/homebrew/bin/node
        Yarn: 1.22.19 - /opt/homebrew/bin/yarn
        npm: 8.12.1 - /opt/homebrew/bin/npm
        Watchman: Not Found
      Managers:
        CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
      SDKs:
        iOS SDK:
          Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
        Android SDK: Not Found
      IDEs:
        Android Studio: 2021.2 AI-212.5712.43.2112.8609683
        Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
      Languages:
        Java: 11.0.15 - /usr/bin/javac
      npmPackages:
        @react-native-community/cli: Not Found
        react: 18.0.0 => 18.0.0 
        react-native: 0.69.0 => 0.69.0 
        react-native-macos: Not Found
      npmGlobalPackages:
        *react-native*: Not Found
    
  10. 592da commented on Jun 23, 2022

    @592da

    Also having this issue after upgrading from 0.68.2 to 0.69
    Any suggestions?

    System:
        OS: macOS 12.4
        CPU: (10) arm64 Apple M1 Max
        Memory: 2.46 GB / 32.00 GB
        Shell: 5.8.1 - /bin/zsh
      Binaries:
        Node: 16.14.2 - /usr/local/bin/node
        Yarn: Not Found
        npm: 8.10.0 - ~/n/bin/npm
        Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
      Managers:
        CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
      SDKs:
        iOS SDK:
          Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
        Android SDK: Not Found
      IDEs:
        Android Studio: Not Found
        Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
      Languages:
        Java: 11.0.15 - /usr/bin/javac
      npmPackages:
        @react-native-community/cli: Not Found
        react: 18.0.0 => 18.0.0
        react-native: 0.69.0 => 0.69.0
        react-native-macos: Not Found
      npmGlobalPackages:
        *react-native*: Not Found
    
    app/node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.m:17:20: error: use of undeclared identifier 'YGValue'
      subview.width = (YGValue) { RCTScreenSize().width, YGUnitPoint };
                       ^
    1 error generated.
    
    
    
    
  11. mfik commented on Jun 23, 2022

    @mfik

    So this has to do with case sensitive file systems. My drive says it isn't, but i believe it was encrypted in the past. The temporary solution is to add this step to the build process, as mentioned : #33648

    This really needs a fix tho, many hours lost by a lot of people.

    rm -rf node_modules ios/Pods
    yarn
    sed -i -e "s/spec.module_name = 'yoga'/spec.module_name = 'Yoga'/g" node_modules/react-native/ReactCommon/yoga/Yoga.podspec
    npx pod-install
    expo run:ios
    
  12. ph4r05 commented on Jun 23, 2022

    @ph4r05
    Contributor

    I have the same problem but @mfik's workaround is not working for me.

    For some reason, the type error is fixed when I rename RCTInputAccessoryShadowView.m to RCTInputAccessoryShadowView.mm so Obj-C++ is used to compile it.

    I had to change node_modules/react-native/Libraries/Text/React-RCTText.podspec so *.mm files are taken into account. After reinstalling pods, type error is fixed. I don't have case-sensitive FS. I am currently investigating why Obj-C++ is able to correctly see types from yoga/Yoga.h types and Obj-C is not. Any ideas?

    patches/react-native+0.69.0.patch:

    diff --git a/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m b/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.mm
    similarity index 100%
    rename from node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m
    rename to node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.mm
    diff --git a/node_modules/react-native/Libraries/Text/React-RCTText.podspec b/node_modules/react-native/Libraries/Text/React-RCTText.podspec
    index 793a8db..e324b03 100644
    --- a/node_modules/react-native/Libraries/Text/React-RCTText.podspec
    +++ b/node_modules/react-native/Libraries/Text/React-RCTText.podspec
    @@ -26,7 +26,7 @@ Pod::Spec.new do |s|
       s.author                 = "Facebook, Inc. and its affiliates"
       s.platforms              = { :ios => "12.4" }
       s.source                 = source
    -  s.source_files           = "**/*.{h,m}"
    +  s.source_files           = "**/*.{h,m,mm}"
       s.preserve_paths         = "package.json", "LICENSE", "LICENSE-docs"
       s.header_dir             = "RCTText"
    
    diff --git a/node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.m b/node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.mm
    similarity index 83%
    rename from node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.m
    rename to node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.mm
    index 8322bfc..47d6b5a 100644
    --- a/node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.m
    +++ b/node_modules/react-native/Libraries/Text/TextInput/RCTInputAccessoryShadowView.mm
    @@ -14,7 +14,7 @@ @implementation RCTInputAccessoryShadowView
     - (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
     {
       [super insertReactSubview:subview atIndex:atIndex];
    -  subview.width = (YGValue) { RCTScreenSize().width, YGUnitPoint };
    +  subview.width = (YGValue) { static_cast<float>(RCTScreenSize().width), YGUnitPoint };
     }
    
     @end

    I've added my changes to #34064

    For completeness, I had to edit also react-native-safe-area-context:

    diff --git a/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.m b/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.mm
    similarity index 88%
    rename from node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.m
    rename to node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.mm
    index 1597bc8..1394e33 100644
    --- a/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.m
    +++ b/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.mm
    @@ -116,16 +116,16 @@ - (void)updateInsets
     
       if (mode == RNCSafeAreaViewModePadding) {
         [self extractEdges:_paddingMetaProps top:&top right:&right bottom:&bottom left:&left];
    -    super.paddingTop = (YGValue){insetTop + top, YGUnitPoint};
    -    super.paddingRight = (YGValue){insetRight + right, YGUnitPoint};
    -    super.paddingBottom = (YGValue){insetBottom + bottom, YGUnitPoint};
    -    super.paddingLeft = (YGValue){insetLeft + left, YGUnitPoint};
    +    super.paddingTop = (YGValue){static_cast<float>(insetTop + top), YGUnitPoint};
    +    super.paddingRight = (YGValue){static_cast<float>(insetRight + right), YGUnitPoint};
    +    super.paddingBottom = (YGValue){static_cast<float>(insetBottom + bottom), YGUnitPoint};
    +    super.paddingLeft = (YGValue){static_cast<float>(insetLeft + left), YGUnitPoint};
       } else if (mode == RNCSafeAreaViewModeMargin) {
         [self extractEdges:_marginMetaProps top:&top right:&right bottom:&bottom left:&left];
    -    super.marginTop = (YGValue){insetTop + top, YGUnitPoint};
    -    super.marginRight = (YGValue){insetRight + right, YGUnitPoint};
    -    super.marginBottom = (YGValue){insetBottom + bottom, YGUnitPoint};
    -    super.marginLeft = (YGValue){insetLeft + left, YGUnitPoint};
    +    super.marginTop = (YGValue){static_cast<float>(insetTop + top), YGUnitPoint};
    +    super.marginRight = (YGValue){static_cast<float>(insetRight + right), YGUnitPoint};
    +    super.marginBottom = (YGValue){static_cast<float>(insetBottom + bottom), YGUnitPoint};
    +    super.marginLeft = (YGValue){static_cast<float>(insetLeft + left), YGUnitPoint};
       }
     }
     
  13. renchap commented on Jun 24, 2022

    @renchap
    Contributor

    Thanks @ph4r05 this indeed makes the build move forward for me (case-insensitive FS as well).

    But it fails a bit later with:

    /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m:17:42: error: missing '#include "yoga/Yoga.h"'; 'YGNodeRef' must be declared before it is used
    static void RCTInlineViewYogaNodeDirtied(YGNodeRef node)
                                             ^
    In module 'React' imported from /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m:8:
    /Users/renchap/dev/project/packages/mobile/ios/Pods/Headers/Public/Yoga/yoga/Yoga.h:34:24: note: declaration here is not visible
    typedef struct YGNode* YGNodeRef;
    

    Once this file has been renamed to RCTBaseTextShadowView.mm, it proceeds until:

    /Users/renchap/dev/notos/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.m:25:3: error: missing '#include "yoga/YGValue.h"'; 'YGValue' must be declared before it is used
      YGValue _paddingMetaProps[META_PROP_COUNT];
      ^
    In module 'React' imported from /Users/renchap/dev/notos/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.h:1:
    /Users/renchap/dev/notos/packages/mobile/ios/Pods/Headers/Public/Yoga/yoga/YGValue.h:35:3: note: declaration here is not visible
    } YGValue;
      ^
    

    It seems to be the same kind of error. Might it be that those .m files are included by libraries, but somehow are no longer correctly picked up by the build system?

    This would explain why it does not happen on a newly created app, and I am hitting more of those than you.

  14. ph4r05 commented on Jun 24, 2022

    @ph4r05
    Contributor

    @renchap great it works for you as well! The patch renames RCTBaseTextShadowView.m to RCTBaseTextShadowView.mm too. I edited the original comment to include also patch to react-native-safe-area-context module which was needed on my side as well. But from what I see now, don't we have the same set of changed files?

  15. renchap commented on Jun 24, 2022

    @renchap
    Contributor

    I missed your RCTBaseTextShadowView.m renaming!

    It now compiles correctly with your 2 patches 🎉

  16. lisong996 commented on Jun 28, 2022

    @lisong996

    same question after install expo

  17. innocodes commented on Jan 11, 2023

    @innocodes

    Thanks @ph4r05 this indeed makes the build move forward for me (case-insensitive FS as well).

    But it fails a bit later with:

    /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m:17:42: error: missing '#include "yoga/Yoga.h"'; 'YGNodeRef' must be declared before it is used
    static void RCTInlineViewYogaNodeDirtied(YGNodeRef node)
                                             ^
    In module 'React' imported from /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m:8:
    /Users/renchap/dev/project/packages/mobile/ios/Pods/Headers/Public/Yoga/yoga/Yoga.h:34:24: note: declaration here is not visible
    typedef struct YGNode* YGNodeRef;
    

    Once this file has been renamed to RCTBaseTextShadowView.mm, it proceeds until:

    /Users/renchap/dev/notos/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.m:25:3: error: missing '#include "yoga/YGValue.h"'; 'YGValue' must be declared before it is used
      YGValue _paddingMetaProps[META_PROP_COUNT];
      ^
    In module 'React' imported from /Users/renchap/dev/notos/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.h:1:
    /Users/renchap/dev/notos/packages/mobile/ios/Pods/Headers/Public/Yoga/yoga/YGValue.h:35:3: note: declaration here is not visible
    } YGValue;
      ^
    

    It seems to be the same kind of error. Might it be that those .m files are included by libraries, but somehow are no longer correctly picked up by the build system?

    This would explain why it does not happen on a newly created app, and I am hitting more of those than you.

    I have a similar issue.

    (node_modules/expo-updates/ios/EXUpdates/AppLoader/EXUpdatesFileDownloader.m:96:35)
    94 | {
    95 | [self downloadDataFromURL:url extraHeaders:extraHeaders successBlock:^(NSData *data, NSURLResponse *response) {
    96 | NSString *hashBase64String = [EXUpdatesUtils base64UrlEncodedSHA256WithData:data];
    | ^ use of undeclared identifier 'EXUpdatesUtils'
    97 | if (expectedBase64URLEncodedSHA256Hash && ![expectedBase64URLEncodedSHA256Hash isEqualToString:hashBase64String]) {
    98 | errorBlock([NSError errorWithDomain:EXUpdatesFileDownloaderErrorDomain
    99 | code:EXUpdatesFileDownloaderErrorCodeFileHashMismatchError

    So I renamed EXUpdatesFileDownloader.m to EXUpdatesFileDownloader.mm

    After renaming the affected file in my own case, I am getting an error:

    error: Build input file cannot be found: '/Users/username/initialDesktop/RN-select-country/app-name/node_modules/expo-updates/ios/EXUpdates/AppLoader/EXUpdatesFileDownloader.m'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target 'EXUpdates' from project 'Pods')

    Did you run patch-package first before running build iOS command again?

  18. innocodes commented on Jan 11, 2023

    @innocodes

    Thanks @ph4r05 this indeed makes the build move forward for me (case-insensitive FS as well).
    But it fails a bit later with:

    /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m:17:42: error: missing '#include "yoga/Yoga.h"'; 'YGNodeRef' must be declared before it is used
    static void RCTInlineViewYogaNodeDirtied(YGNodeRef node)
                                             ^
    In module 'React' imported from /Users/renchap/dev/project/node_modules/react-native/Libraries/Text/BaseText/RCTBaseTextShadowView.m:8:
    /Users/renchap/dev/project/packages/mobile/ios/Pods/Headers/Public/Yoga/yoga/Yoga.h:34:24: note: declaration here is not visible
    typedef struct YGNode* YGNodeRef;
    

    Once this file has been renamed to RCTBaseTextShadowView.mm, it proceeds until:

    /Users/renchap/dev/notos/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.m:25:3: error: missing '#include "yoga/YGValue.h"'; 'YGValue' must be declared before it is used
      YGValue _paddingMetaProps[META_PROP_COUNT];
      ^
    In module 'React' imported from /Users/renchap/dev/notos/node_modules/react-native-safe-area-context/ios/RNCSafeAreaShadowView.h:1:
    /Users/renchap/dev/notos/packages/mobile/ios/Pods/Headers/Public/Yoga/yoga/YGValue.h:35:3: note: declaration here is not visible
    } YGValue;
      ^
    

    It seems to be the same kind of error. Might it be that those .m files are included by libraries, but somehow are no longer correctly picked up by the build system?
    This would explain why it does not happen on a newly created app, and I am hitting more of those than you.

    I have a similar issue.

    (node_modules/expo-updates/ios/EXUpdates/AppLoader/EXUpdatesFileDownloader.m:96:35)
    94 | {
    95 | [self downloadDataFromURL:url extraHeaders:extraHeaders successBlock:^(NSData *data, NSURLResponse *response) {
    96 | NSString *hashBase64String = [EXUpdatesUtils base64UrlEncodedSHA256WithData:data];
    | ^ use of undeclared identifier 'EXUpdatesUtils'
    97 | if (expectedBase64URLEncodedSHA256Hash && ![expectedBase64URLEncodedSHA256Hash isEqualToString:hashBase64String]) {
    98 | errorBlock([NSError errorWithDomain:EXUpdatesFileDownloaderErrorDomain
    99 | code:EXUpdatesFileDownloaderErrorCodeFileHashMismatchError

    So I renamed EXUpdatesFileDownloader.m to EXUpdatesFileDownloader.mm

    After renaming the affected file in my own case, I am getting an error:

    error: Build input file cannot be found: '/Users/username/initialDesktop/RN-select-country/app-name/node_modules/expo-updates/ios/EXUpdates/AppLoader/EXUpdatesFileDownloader.m'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target 'EXUpdates' from project 'Pods')

    Did you run patch-package first before running build iOS command again?

    I solved the new error by running pod deintegrate, and pod install.

    However, this led to more errors in the code after running 'npm run ios' command.

    Any fix for this yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions