4

I am trying to run my IOS app with react native, but I need to update my Pods. so I run on terminal:

cd iOS && pod install

But I get this error on the title

internal/modules/cjs/loader.js:888
  throw err;
  ^

Error: Cannot find module '/Users/my-user/Documents/Test/my-app/ios/undefined'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

[!] Invalid `Podfile` file: 767: unexpected token at ''.
#  from /Users/my-user/Documents/Test/my-app/ios/Podfile:12
#  -------------------------------------------
#  
>    use_native_modules!
#  end
#  -------------------------------------------

What should I Do?

My Podfile is as follow

# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'


target 'MyApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp

  use_native_modules!
end

and my package.json file uses this dependencies:

"dependencies": {
  "@react-native-community/async-storage": "^1.12.1",
  "@react-native-community/cli-platform-ios": "^3.0.0",
  "@react-native-community/netinfo": "8.3.0",
  "@sentry/react-native": "3.4.3",
  "@virgilsecurity/e3kit": "^0.7.0-beta.2",
  "@virgilsecurity/key-storage-rn": "^0.2.1",
  "appcenter-cli": "^2.1.2",
  "moment": "2.29.3",
  "react": "16.9.0",
  "react-native": "0.61.3",
  "react-native-calendars": "1.259.0",
  "react-native-code-push": "6.0.0",
  "react-native-extended-stylesheet": "^0.12.0",
  "react-native-fast-image": "^8.5.11",
  "react-native-fbsdk": "^3.0.0",
  "react-native-firebase": "^5.5.6",
  "react-native-fs": "^2.14.1",
  "react-native-gifted-chat": "^0.13.0",
  "react-native-image-picker": "^1.0.2",
  "react-native-keep-awake": "^4.0.0",
  "react-native-keychain": "^4.0.1",
  "react-native-masked-text": "^1.13.0",
  "react-native-push-notification": "^8.1.1",
  "react-native-twilio-video-webrtc": "^2.0.0",
  "react-native-vector-icons": "^5.0.0",
  "react-native-virgil-crypto": "^0.6.1",
  "react-native-webview": "^7.4.1",
  "react-redux": "^8.0.2",
  "react-router": "^5.1.2",
  "react-router-dom": "^5.1.2",
  "react-router-native": "^5.1.2",
  "realm": "6.0.3",
  "redux": "^4.2.0",
  "redux-thunk": "^2.4.1"
},

if I take use_native_modules! out of the code, it works properly. But with him it doesn't

Germano
  • 358
  • 1
  • 2
  • 13
  • It happened in React Native 0.69.0. I have also followed the proper migration guidelines but it didn't work. I am also waiting for the resolution. – IOS Dev Jul 14 '22 at 05:24
  • hey @IOSDev , in my case I am using "react-native": "0.61.3", – Germano Jul 14 '22 at 11:14

5 Answers5

8

I just deleted node_modules, and then ran npm i and then ran pod install to solve the error

Mufaddal Hamid
  • 281
  • 3
  • 12
5

Finally!!! To install my pods, normally, I just needed to do 3 things.

1- Remove the package @react-native-community/cli-platform-ios from package.json

2- on terminal, access the main app folder and update changes on node_modules

yarn

3- Access iOS page and install the pods

cd ios && pod install
Germano
  • 358
  • 1
  • 2
  • 13
4

I fixed this issue on my machine by disabling VS Code's debugger Auto Attach feature. The feature was causing Node to spew extra console output, which the native_modules.rb file could not parse.

This error could be caused from any number of local configuration issues. So my solution may not work for you. If disabling VS Code Auto Attach doesn't solve it for you, here is how you can investigate more:

unexpected token at '' is a JavaScript error. If you go to the Ruby file where the error originates (usually ../node_modules/@react-native-community/cli-platform-ios/native_modules.rb), you can see that it is trying to open some JS files from your node_modules using Node. In your terminal, cd to the location of the native_modules.rb file and try to execute the Node commands on your terminal - you may get more clues about what is going on on your system. Good luck.

prcodes
  • 41
  • 1
  • 1
    it fixed when i removed cli-platform-ios, there was no need for my code, thanks! – Germano Nov 07 '22 at 16:05
  • 1
    Thank you. I kept using the integrated terminal and it failed. I used a separate Bash terminal and it worked. Thank you! – Tanner Plauché Jan 23 '23 at 19:51
  • I was running `pod install` in VSCode and it didn't work, turning the `Debug: Toggle Auto Attach` to off worked for me. Good find, can't believe it is due to parsing output issue.. thanks a lot! – CyberMew Jun 07 '23 at 04:23
4

I was successful when I did "yarn install" again

0

In my case, it was node 14. Removing package-lock.json and node_moduled didn't work

I switched to node 20, remove package-lock.json and node_module. Now the iOS build is working