-
Notifications
You must be signed in to change notification settings - Fork 216
Description
Environment
npx create-react-native-library --version
0.23.3
node --version
v16.15.0
ruby --version
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]
xcode
14.0.1
iOS
16.0.2
Description
I have been struggling for a long day to run the iOS example application of the Native Module npm package generated by the CLI because the compiler was not able to find the program entryoint (index.js).
I provided the fix in hope to help those that might have the same issue I had.
Reproducible Demo
Create a project:
npx create-react-native-library test
Go through the wizard and select the type of library to be Native Module and language Kotlin & Swift
Then install dependencies for the project:
cd test/
yarn
cd ./ios/example
pod install
cd -
At this point I generally need to configure signing capabilities in XCode.
Then I run the example:
yarn example ios --device
Finally, I get the following error:
error The resource `/Users/mthibault/src/smartd/mobile/test/example/index.js` was not found.
Error: The resource `/Users/mthibault/src/smartd/mobile/test/example/index.js` was not found.
at /Users/mthibault/src/smartd/mobile/test/example/node_modules/metro/src/IncrementalBundler.js:297:24
at gotStat (node:fs:2654:21)
at FSReqCallback.oncomplete (node:fs:198:21)
info Run CLI with --verbose flag for more details.
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/mthibault/Library/Developer/Xcode/DerivedData/TestExample-fgbncwdujcywafgnjjvxjnyejmef/Build/Intermediates.noindex/TestExample.build/Debug-iphoneos/TestExample.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'TestExample' from project 'TestExample')
(1 failure)
Cause
Obviously, the problem comes from the build phase called Bundle React Native code and images which is not configured to support typescript (index.tsx). It took me a while to figure that out because XCode was not very explicit.
The fix
In XCode,
- open the workspace under example/ios
- select the project and the target
- select the Build phases tab
The code of the build phase should be re-written to target the index.tsx
:
Before:
set -e
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
after
set -e
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh index.tsx