Invalid `Podfile` file: 767: unexpected token at ''
Asked Answered
H

13

14

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

Hoke answered 13/7, 2022 at 19:34 Comment(2)
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.Psychopharmacology
hey @IOSDev , in my case I am using "react-native": "0.61.3",Hoke
H
6

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
Hoke answered 14/7, 2022 at 12:40 Comment(2)
I didn't have cli-platform-ios, but yarn install && pod install did it for meDavide
in my package.json, he was the problemHoke
S
15

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

Spencerspencerian answered 5/11, 2022 at 9:52 Comment(5)
in my case, i needed to remove @react-native-community/cli-platform-iosHoke
this worked on my endIt
This worked in my case, thank you.Deration
This will work :)Obla
For me, i was using node version 14. After i updated to 20, it started to work.Transpacific
E
14

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.

Erythropoiesis answered 14/10, 2022 at 7:11 Comment(5)
it fixed when i removed cli-platform-ios, there was no need for my code, thanks!Hoke
Thank you. I kept using the integrated terminal and it failed. I used a separate Bash terminal and it worked. Thank you!Headwaiter
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!Muggy
Thanks! I spent too many hours trying to fix it and your answer fixed it.Shovel
I had this issue a couple of weeks ago, found that temporarily disabling VS Code's auto attach worked, upvoted the answer and forgot all about it. Today, I couldn't work out why pod install was suddenly not working and after banging my head against the wall for an hour or so, came back to the same page, noticed I had upvoted this answer and once again disabled auto attach for the win. Hopefully leaving this comment will help bring me back to this answer more quickly next time.Cortico
P
8

You should check your npm version, I was trying to run pod install with an old npm version (6.14.18), then I switched to a newer npm version (18.18.0) and it worked! :).

Note: To be able to successfully manage multiple Node versions on your macOS, I recommend using nvm, a Node Version Manager. With this little fella, you can easily jump from one Node version to another. You can also install multiple versions and select one specific version for each project that you have.

Periwig answered 4/12, 2023 at 19:47 Comment(3)
This worked in my case. And if you're wondering how to switch the node version, you can install and use nvm (node version manager) and for example in your project directory use this command 'nvm use node 18' (need to have node 18 installed)Melamine
@AwabIjaz, I've edited my post and added more information about nvm. :)Periwig
Yes this is correct, i also faced this and resolved with upgrade node versionSavoy
H
6

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
Hoke answered 14/7, 2022 at 12:40 Comment(2)
I didn't have cli-platform-ios, but yarn install && pod install did it for meDavide
in my package.json, he was the problemHoke
S
4

I was successful when I did "yarn install" again

Sandrasandro answered 29/1, 2023 at 18:32 Comment(1)
what about your package.json configuration?Hoke
D
4

In my case, it happened when I upgraded my project react-native version to 0.72.7 and remove the package="..." in root <manifest > of main/AndroidManifest.xml.

Not sure why react-native is getting package name from Android to iOS podfile. But just re-add the package="..." fixed the issue.

Decrial answered 21/11, 2023 at 4:0 Comment(1)
same resolution for meEarreach
A
2

I tried several times to delete node_modules and npm i && cd ios && pod install. All of them failed.

Here is how I make it work.

  1. I removed package-lock.json and node_modules.
  2. I deleted the config in react-native.config.js because there is a config automaticPodsInstallation: true. I changed it to false and it does not work, so I just deleted this attribute. I think it is the main reason of my installation failure. When I use --verbose to install it, it shows:
[!] Invalid `Podfile` file: unexpected token at 'Config Validation Error: "project.ios.automaticPodsInstallation" is not allowed

3.Run yarn, cd ios && pod install

It works for me.

Avelar answered 7/12, 2023 at 21:29 Comment(1)
Thank You!!! you can comment the line instead of deleting the file.Pasadis
C
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

Cacodemon answered 18/8, 2023 at 10:42 Comment(0)
S
0

Try to upgrade node version. i solved this error with update node version.

Savoy answered 30/1, 2024 at 12:28 Comment(0)
B
0

I had a slightly different but similar issue, I was facing the following error:

Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: 809: unexpected token at ''.

My issue was that I was running Node through nvm for management of different node versions with different projects.

My system node version was quite old, and running pod install with my system node version was failing with this error.

I simply needed to use nvm list to see the different node I had installed, and then nvm use vx.x.x to select the more updated version that I wanted to use. Once I had my terminal using the more recent version of node, then running pod install worked for me.

Bhutan answered 20/2, 2024 at 23:53 Comment(0)
S
0

my issue was react-native-pdf & react-native-blob-util .

after removing them using

yarn remove react-native-pdf 

yarn remove react-native-blob-util 

everything worked as expected!

Saffier answered 13/4, 2024 at 1:2 Comment(0)
C
0

If you're encountering this problem, simply update the React Native version in your package.json file. For me, it worked with version 0.73.5.

The issue is related to the version of React Native you are using. Updating to a newer version can resolve compatibility and functionality problems.

Clywd answered 21/5, 2024 at 9:13 Comment(0)
M
0

I have different node version mentioned in .xcode.env.local (export NODE_BINARY=/Users/mainak-macmini/.nvm/versions/node/v20.13.1/bin/node ) and the node version I was installing was wrong for node_modules

Marucci answered 17/7, 2024 at 19:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.