Podfile install failed - Can't find node modules - react-native

Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: cannot load such file -- ./scripts/autolinking.
# from /Users/developer/Documents/Project1/ios/Podfile:1
-------------------------------------------
> require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
# require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
-------------------------------------------
sh: node: command not found
I've been trying to figure this out all day and still can't figure out what the issue is. I've got node in my paths so it can find the command.
I figured out if I were to change the first require line to File.join('node_modules/expo/scripts/autolinking') it manages to execute, however then it throws the same issue for a file within the node modules, which i can't go through and change all the node_modules manually.
Does anyone know why this is happening?

On Mac M1
Install CocoaPod from HomeBrew to your terminal in the project folder or globally
Delete existing Podfile if any .
If none, good dont worry
run pod init
This will create a new Podfile
Then in ios folder run pod install or npx pod-install
if you get errors below, you probably have wrong .env
ERROR: SyntaxError: JSON Parse error: Unexpected identifier "undefined"
ERROR: Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.`
Hope this helps :)

Related

ReferenceError: Can't find variable: W4r in React Native

After adding the new files from a different folder I got this error:
ReferenceError: Can't find variable: W4r
ERROR Invariant Violation: "main" has not been registered. This can happen if:
Metro (the local dev server) is running from the wrong folder. Check if Metro is running, stop it, and restart it in the current project.
A module failed to load due to an error and AppRegistry.registerComponent wasn't called.
I did not find the "W4r" in anywhere in my code
Remove node_modules folder
Install dependencies (npm i)
Close android emulator & close metro window
cd android && gradlew clean
npx react-native start --reset-cache
After "Metro" opens, close it
npm run android
I try this when my env no respond, hope its help you.

React Native run-android on Apple M1 chip throwing error, "Could not open dsl generic class cache for script"

I am building a mobile application using React-Native. I am now trying to run my application on Android Emulator. First, this is the continuation of this question. I installed the Android Studio and configured the environment as I mentioned in the previous question.
This is what I did to fix the error from previous question.
I changed the line 13 in android/gradle.properties to this:
org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
When I run "react-native run-android" command this time, I am getting the error. The error is saying it could not find '/Users/waihein/Desktop/Code/shar-kya-mal-app/node_modules/#react-native-community/cli-platform-android/native_modules.gradle' file.
So I run npm i #react-native-community/cli-platform-android command to install the required package.
The I delete node_modules folder and run "npm install" again. Then I run "react-native run-android". I am getting the following error this time.
* Where:
Settings file '/Users/waihein/Desktop/Code/shar-kya-mal-app/android/settings.gradle' line: 8
* What went wrong:
A problem occurred evaluating settings 'sharkyamalapp'.
> Could not open dsl generic class cache for script '/Users/waihein/Desktop/Code/shar-kya-mal-app/node_modules/#react-native-community/cli-platform-android/native_modules.gradle' (/Users/waihein/.gradle/caches/6.8/scripts/a43tr593rdpk11ispliu0nu14).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
But the file is there I can see it in the node_modules folder. How can I fix it?

How to fix bundler module resolution issue without deleting/installing npm packages?

Goal: successfully build & bundle react native project using react-native-agora v3.0.1-rc.4, while preserving npm packages that i have edited.
I was told to try updating to this version by agora support staff. after a bunch of errors and managing them, I come to another issue. the project now builds, but won't successfully bundle. bundle process fails (on iOS, haven't tried android yet):
error: bundling failed: Error: Unable to resolve module `./AgoraView.native` from `node_modules/react-native-agora/lib/index.js`:
None of these files exist:
* node_modules/react-native-agora/lib/AgoraView.native(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
* node_modules/react-native-agora/lib/AgoraView.native/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
RN v0.61.5
Im not sure why its trying to resolve ./AgoraView.native. As I dont have it explicitly referenced anywhere.
So far ive tried:
npm cache clean --force
uninstalling and reinstalling react-native-agora
pod install
cleaning build folder and rebuilding
How to resolve?
Did you try to delete node_modules and re-install it and clean build folder of iOS. I think it cached the last version of react-native-agoro.
An option if you have edited npm packages, and thus would prefer to avoid deleting, re-installing, and re-editing said packages this is what worked for me:
react-native start --reset-cache

bundling failed: Error: ENOENT: no such file or directory, scandir React Native

I have no error in my project. But the build not successfully load. see the below image. for more details for error. I am using the below command to run the build react-native run-android but the npm failed to create the build. this image directory exists and I give the correct path for images. Thanks in advance.
-root
--assets
---images
---- All Images here.
../../assets/images/sky-img.jpg use this in code.
Just closing and re-opening the cmd terminal or whatever you are using to run the metro bundler worked for me.
Just reset the cache of your Metro Bundler with:
npm start -- --reset-cache
This is happening because the bundler needs to refresh it's existing bundles and the path you previously set.
Make sure you run the command from the root directory and not from android directory.
android> cd..
project> npx react-native run-android --variant=release

Metro Bundler error: Expected path […] to be relative to one of the project roots

When trying to run my React Native app I get this error:
error: bundling failed: Error: Expected path `/Users/jgallaso/Projects/aerogear/aerogear-react-native-core/index.js` to be relative to one of the project roots
at toLocalPath (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/lib/toLocalPath.js:33:9)
at ModuleCache.getModule (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/ModuleCache.js:94:20)
at ModuleResolver._getFileResolvedModule (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:320:42)
at ModuleResolver.resolveDependency (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:311:989)
at ResolutionRequest.resolveDependency (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:96:16)
at DependencyGraph.resolveDependency (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:269:4352)
at /Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:201:36
at next (native)
at step (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:306)
at /Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:536
BUNDLE [android, dev] ./index.js ▓▓▓▓▓▓▓▓▓░░░░░░░ 56.6% (331/440), failed.
My app has a dependency installed aerogear-react-native-core that is a Native Module. Source code is at: https://github.com/josemigallas/aerogear-react-native-core
This package on the other hand depends on other TS one (I ignore if this is problematic) and this code is located at: https://github.com/josemigallas/aerogear-js-sdk/tree/poc_react_native_library/packages/core
And the app code that actually tries to use all this is located at: https://github.com/josemigallas/aerogear-js-sdk/tree/poc_react_native_library/example/react-native
This means:
App
└─┬ aerogear-react-native-core#0.0.2
└── #aerogearmobile/core#1.0.0
Since this is all at development stage, nothing is pushed to npmjs, I'm just using npm link to include all dependencies.
Honestly I don't have a clue why this is failing, without the second dependency everything worked all right so that makes me think typescript has something to do. However, the error is complaining about aerogear-react-native-sdk's index.js file so maybe the error is related with the link.
I tried deleting all caches, re-installing npm modules, re-running the bundler many times...
If you have used "npm link" in the project, that might be the reason. Metro Bundler does not work with symlink correctly. Try to install the dependency without using "npm link".