react-native: Redefinition of 'Native....SpecJSI' . Error when building with a custom turbo module
Description
Redefinition of ‘Native…SpecJSI’ . Error when building with a custom turbo module. I strictly followed the instructions for create turbo module https://reactnative.dev/docs/the-new-architecture/pillars-turbomodules
Steps to reproduce
–
React Native Version
0.73.2
Affected Platforms
Runtime - iOS
Areas
TurboModule - The New Native Module System
Output of npx react-native info
System:
OS: macOS 14.2.1
CPU: (12) arm64 Apple M3 Pro
Memory: 99.55 MB / 18.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.19.0
path: ~/.nvm/versions/node/v18.19.0/bin/node
Yarn:
version: 1.22.21
path: /opt/homebrew/bin/yarn
npm:
version: 10.2.3
path: ~/.nvm/versions/node/v18.19.0/bin/npm
Watchman:
version: 2023.12.04.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.14.3
path: /Users/skinnynpale/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK: Not Found
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11076708
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.9
path: /usr/bin/javac
Ruby:
version: 3.0.6
path: /Users/skinnynpale/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.73.2
wanted: 0.73.2
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
/Users/skinnynpale/Library/Developer/Xcode/DerivedData/a4ord-cnymkqjxmmqjnmfdnnckwsbdoigs/Build/Products/Debug-iphonesimulator/React-Codegen/React_Codegen.framework/Headers/RTNCustomAppBrowserSpec/RTNCustomAppBrowserSpec.h:34:22 Redefinition of 'NativeCustomAppBrowserSpecJSI'
About this issue
- Original URL
- State: open
- Created 5 months ago
- Reactions: 1
- Comments: 21 (8 by maintainers)
Commits related to this issue
- Fix the Redefinition of 'NativeXXXSpecJSI' error with Frameworks Summary: When using frameworks on iOS, there is a possibility that modules import the Spec.h file twice and this might end up in a Red... — committed to cipolleschi/react-native by cipolleschi 3 months ago
- Fix the Redefinition of 'NativeXXXSpecJSI' error with Frameworks (#44005) Summary: When using frameworks on iOS, there is a possibility that modules import the Spec.h file twice and this might end u... — committed to cipolleschi/react-native by cipolleschi 3 months ago
- Fix the Redefinition of 'NativeXXXSpecJSI' error with Frameworks (#44005) Summary: When using frameworks on iOS, there is a possibility that modules import the Spec.h file twice and this might end u... — committed to cipolleschi/react-native by cipolleschi 3 months ago
- Fix the Redefinition of 'NativeXXXSpecJSI' error with Frameworks (#44005) Summary: When using frameworks on iOS, there is a possibility that modules import the Spec.h file twice and this might end u... — committed to cipolleschi/react-native by cipolleschi 3 months ago
- Fix the Redefinition of 'NativeXXXSpecJSI' error with Frameworks (#44005) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44005 When using frameworks on iOS, there is a... — committed to facebook/react-native by cipolleschi 3 months ago
Yes,
#pragma oncedoesn’t seem to work on iOS when using codegen.I do agree to everything @eflashcards mentioned:
#includeguards here.Hopefully, we will be able to fix this for good soon and systematically…
I managed to repro it locally! 😄
One think I noticed is that both
RNTCalculator.handRNTCalculator.mmboth import the same file.So, what happens is that, when Xcode builds the
RNTCalculator.mm, it takes theRNTCalculatorSpeconce because it has been explicitly imported by line 1, and then it takes it another time because the#import "RNTCalculator.h"import theRNTCalculatorSpectransitively.The first line can be removed:
And everything will work fine ==> The error goes away.
That said, this is a bit brittle. I’d like to see if we can find a systematic approach to solve this.
cc. @eflashcards @dylancom @dumbravaandrei22 @skinnynpale @javache
We’ll probably end up applying the @eflashcards suggestions in codegen directly. For some reasons,
#pragma oncedoes not work in this case.@eflashcards thanks for the reproducer steps and the heads up with the pragmas. It might be that we forgot to add
#pragma oncein the codegen? 🤔I’m sorry, but I need a reproducer from you, guys. I build new empty apps with React Nativ and the New Architecture every day as that is my main focus, but I can’t reproduce this issue in any way. 😦
@eflashcards which commands are you using to create an empty project? @dumbravaandrei22 are you sure you followed the tutorial correctly? For example, here skinnynpale deleted a line inadvertently and it make everything fail… @dylancom can you provide a reproducer?
thanks, I’ll have a look at this tomorrow morning!