CLI: unexpected token '?'

This issue has been created since 2022-09-22.

Description

Hi guys,

just created a new project and it is throwing this error when doing archive on iOS and when doing build on Android

Showing Recent Messages

  • /usr/local/bin/node /Users/hardik/Documents/GitHub/ReactNApp/node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/hardik/Library/Developer/Xcode/DerivedData/ArcedirovNew-cdkamivgjmneqpgzgxxedswjccki/Build/Intermediates.noindex/ArchiveIntermediates/ReactNApp/BuildProductsPath/Release-iphoneos/main.jsbundle --assets-dest /Users/hardik/Library/Developer/Xcode/DerivedData/ReactNApp-cdkamivgjmneqpgzgxxedswjccki/Build/Intermediates.noindex/ArchiveIntermediates/ArcedirovNew/BuildProductsPath/Release-iphoneos/ArcedirovNew.app

/Users/hardik/Documents/GitHub/ReactNApp/node_modules/@react-native-community/cli/build/index.js:156

cmd.option(opt.name, opt.description ?? '', opt.parse || (val => val), typeof opt.default === 'function' ? opt.default(rest[0]) : opt.default);

Please advice how to fix this. thanks

Version

0.70.1

Output of npx react-native info

System:
OS: macOS 13.0
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 365.09 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
Watchman: 2022.02.28.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
Android SDK:
API Levels: 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
Build Tools: 29.0.2, 29.0.3, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0
System Images: android-21 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-24 | Android TV Intel x86 Atom, android-24 | Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-25 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-27 | Intel x86 Atom, android-27 | Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64, android-30 | Google Play Intel x86 Atom, android-31 | Google Play Intel x86 Atom_64, android-N | Android Wear ARM EABI v7a, android-N | Android Wear Intel x86 Atom, android-N | Intel x86 Atom, android-N | Intel x86 Atom_64
Android NDK: 21.3.6528147
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9014738
Xcode: 14.0/14A309 - /usr/bin/xcodebuild
Languages:
Java: 18.0.2 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.1 => 0.70.1
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Trying to build on Android
Archive on iOS for app store upload

Snack, code example, screenshot, or link to a repository

https://pasteboard.co/jF639A0h1o6b.png

saravanakumargn wrote this answer on 2022-09-23

I am getting this Error in Xcode while building & Archive.

/node_modules/@react-native-community/cli/build/index.js:156
    cmd.option(opt.name, opt.description ?? '', opt.parse || (val => val), typeof opt.default === 'function' ? opt.default(rest[0]) : opt.default);
                                          ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:1072:16)
    at Module._compile (internal/modules/cjs/loader.js:1122:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
+ [[ '' != true ]]
+ cp /Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/main.jsbundle /Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/ReactNative.app/
cp: /Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/main.jsbundle: No such file or directory
+ BUNDLE_FILE=/Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/ReactNative.app/main.jsbundle
+ [[ false != true ]]
+ [[ ! -f /Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/ReactNative.app/main.jsbundle ]]
+ echo 'error: File /Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/ReactNative.app/main.jsbundle does not exist. This must be a bug with React Native, please report it here: https://github.com/facebook/react-native/issues'
error: File /Users/saravanakumar/Library/Developer/Xcode/DerivedData/ReactNative-exomamucwknejgecicizjaevjbgd/Build/Products/Release-iphonesimulator/ReactNative.app/main.jsbundle does not exist. This must be a bug with React Native, please report it here: https://github.com/facebook/react-native/issues
+ exit 2

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: macOS 12.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 72.03 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
    Watchman: 2022.01.03.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK:
      API Levels: 23, 26, 28, 30, 31, 33
      Build Tools: 22.0.1, 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
      System Images: android-R | Google APIs Intel x86 Atom, android-R | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7678000
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.13 - /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: ^0.70.1 => 0.70.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
cortinico wrote this answer on 2022-09-24

/Users/hardik/Documents/GitHub/ReactNApp/node_modules/@react-native-community/cli/build/index.js:156

cmd.option(opt.name, opt.description ?? '', opt.parse || (val => val), typeof opt.default === 'function' ? opt.default(rest[0]) : opt.default);

Hi @harrymash2006
Thanks for reporting this issue.

It seems like this issue is related to the CLI. Can I ask you to open another issue against this other repository:

https://github.com/react-native-community/cli/issues

Please link against this one and we'll sort things out.

mantegnous wrote this answer on 2022-09-24

same bug after updating to react 0.70.1 from 0.67.4

if i do npx react-native info, the cmd return me: Unexpected token '?'

JamesKEbert wrote this answer on 2022-09-24

I also ran into this! The issue at least in my case was the node export was pointing to the default installed version on the Mac, NOT the nvm managed version. On iOS this can be seen by a log Node found at: ${NODE_BINARY}.
This was due to not having a .xcode.env file (whoops RN updating and missed this) and not having my NVM_DIR set in my bash path settings (since Xcode uses bash instead of zsh), which I did via these instructions.
This might not be the exact issue observed here, but maybe it helps somebody!

mantegnous wrote this answer on 2022-09-26

Update note js to 16 resolve this problem

saravanakumargn wrote this answer on 2022-09-27

Update to NodeJS 16 is the solution for SyntaxError: Unexpected token '?' and not i am able to build the App using XCode.

theonetheycallneo wrote this answer on 2022-09-28

Yes, I'm seeing this as well... I tried these node versions:

nvm use 16.13.1
nvm use 16.17.1
nvm use 18.9.1

[!] Invalid `Podfile` file: 859: unexpected token at 'info Run CLI with --verbose flag for more details.
'.

 #  from /Users/neo/Projects/vatom-inc/wallet/apps/wallet/ios/Podfile:44
 #  -------------------------------------------
 #    use_expo_modules!
 >    config = use_native_modules!
 #
 #  -------------------------------------------
Couldn't install Pods. Updating the Pods project and trying again...
Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: 859: unexpected token at 'info Run CLI with --verbose flag for more details.
'.

 #  from /Users/neo/Projects/vatom-inc/wallet/apps/wallet/ios/Podfile:44
 #  -------------------------------------------
 #    use_expo_modules!
 >    config = use_native_modules!
 #
 #  -------------------------------------------

I confirmed the node -v is in my path as well:

➜  node -v
v16.13.1
➜  which node
/Users/neo/.nvm/versions/node/v16.13.1/bin/node
npx react-native info
warn Package @sentry/react-native contains invalid configuration: "dependency.platforms.ios.sharedLibraries" is not allowed,"dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
warn Package react-native-flipper contains invalid configuration: "dependency.platforms.ios.project" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
info Fetching system and libraries information...
System:
   OS: macOS 12.6
   CPU: (10) arm64 Apple M1 Max
   Memory: 4.37 GB / 64.00 GB
   Shell: 5.8.1 - /bin/zsh
 Binaries:
   Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
   Yarn: 1.22.19 - ~/Projects/vatom-inc/wallet/node_modules/.bin/yarn
   npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
   Watchman: 2022.08.15.00 - /opt/homebrew/bin/watchman
 Managers:
   CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
 SDKs:
   iOS SDK:
     Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
   Android SDK:
     API Levels: 29, 30, 31, 32, 33
     Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0, 33.0.0
     System Images: android-30 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-32 | Google APIs ARM 64 v8a
     Android NDK: Not Found
 IDEs:
   Android Studio: 2021.2 AI-212.5712.43.2112.8815526
   Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
 Languages:
   Java: 11.0.11 - /usr/bin/javac
 npmPackages:
   @react-native-community/cli: Not Found
   react: 18.2.0 => 18.2.0
   react-native: 0.69.5 => 0.69.5
   react-native-macos: Not Found
 npmGlobalPackages:
   *react-native*: Not Found
info React Native v0.70.1 is now available (your project is running on v0.69.5).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.70.1.
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.69.5.
info To upgrade, run "react-native upgrade".
alariej wrote this answer on 2022-09-28

Also seeing this exact issue when trying to archive app in xcode after upgrading RN from 0.69.4 to 0.70.1

Node 16 is installed via nvm. Everything worked perfectly until now.


EDIT: Solved by

  1. manually removing an old version of node (in /usr/local/bin/) that was apparently used by the sh shell (default shell used by xcode)
  2. linking the nvm node installation by running ln -s $(which node) /usr/local/bin/node in a sh shell
chrisribal wrote this answer on 2022-09-29

I had the exact same issue. Running npx react-native run-android worked fine. Opening the upgraded project in Android Studio on my Ubuntu 22.04 machine resulted in the mentioned error.

In my case, I figured out, that i had two versions of node installed:

  • System-wide Node 12 (!!) via package manager (/usr/bin/node)
  • Locally NVM managed Node 17.2.0 (~/.nvm/versions/node/v17.2.0/bin/node)

Gradle seemed to use the system-wide Node 12 from /usr/bin/node, because it doesn't pick up the NVM Paths. So i removed it from the system via apt remove nodejs.

As expected, opening the project again in Android Studio now resulted in an error, because node was not found:
Caused by: java.io.IOException: Cannot run program "node" (in directory "/home/chris/documents/my-app/android"): error=2, File or directory not found

Finally I manually linked the "system node binary" to my NVM installed version:
ln -s $(which node) /usr/bin/node

Now my project is building fine. Maybe that helps.

cortinico wrote this answer on 2022-09-30

Closing as this issue is related to local environment setup

More Details About Repo
Owner Name facebook
Repo Name react-native
Full Name facebook/react-native
Language JavaScript
Created Date 2015-01-09
Updated Date 2022-10-07
Star Count 105180
Watcher Count 3671
Fork Count 22481
Issue Count 2230

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Access control for browsers stops working when basic auth is enabled 12 2018-04-06 2022-08-26
Compilation problem with HLSL 2021 2 2022-09-04 2022-09-18
AssertionError: Labels already generated. Remove or choose new name for labels 2 2022-06-16 2022-10-05
Align content in CTKButtons 3 2022-06-07 2022-09-19
Put together some documentation on meshing 2 2021-12-22 2022-10-05
Tunnel agent exception error 5 2020-03-20 2022-10-05
allow_unreachable=True) # allow_unreachable flag RuntimeError: derivative for to_sparse is not implemented 1 2021-08-31 2022-08-03
Aqara Single Switch Module T1 (No Neutral) 2 2022-09-24 2022-10-04
Deprecated warning part2 0 2022-05-17 2022-09-14
Overflow in card title 0 2021-07-07 2022-09-19
BUG: Inconsistency in `np.nanmin` and similar with `nat` in non-array 1 2022-01-19 2022-09-11
Incomprensible type for hole 0 2022-09-23 2022-09-26
[BUG] Liquid Format handling list loop as input 6 2022-01-12 2022-08-18
Struggling to publish the code to shiny? 3 2017-08-06 2022-10-02
导出数字格式代码中是4,文档中却说是10 0 2021-04-27 2022-09-30
Online form development and creating form functions have stored XSS 2 2020-09-18 2022-09-01
More readable package and long help comment rendering 3 2018-09-28 2022-09-07
Error when running "python run.py -e prototype_10" for Dendrites project 4 2022-03-22 2022-09-15
going_beyond_the_point_neuron_"python run.py -e prototype_10" 0 2022-04-27 2022-09-15
As a ..., I want to ..., so that ... 0 2022-05-23 2022-07-16
[FEATURE REQUEST] Refactor `require` to use `pcall` in language configurations 0 2022-08-01 2022-09-26
Include PySocks package in st2client module. 4 2021-11-26 2022-09-26
服务部署成功后,按照bc.encode执行之后没有任何反馈的停滞了 16 2019-12-09 2022-09-25
Cannot recognize the mouse left-button double click event. 1 2021-12-08 2022-10-02
websocket configuration with nginx 2 2021-10-27 2022-08-21
[Task]: Estimate performance improvement from moving away from styled components. 0 2022-08-16 2022-08-29
wireguard Makefile arch/arm64/Makefile: No such file or directory 3 2020-09-11 2022-09-11
Unable to Update records. 403 Forbidden error. 5 2020-07-24 2022-09-28
CustomerError: Missing frontend definition in buildspec 4 2021-12-13 2022-09-09
TypeError: this.getOptions is not a function 2 2021-02-07 2022-09-26
Importing css or scss file no longer possible 1 2020-08-27 2022-09-26
Account recovery request 0 2022-06-03 2022-08-24
[cloud_firestore] Snapshot lost attributes changes after offline updates 2 2022-04-06 2022-09-10
Any suggestion to generate 1-D vectors using diffusion model 2 2022-06-24 2022-09-28
Trailer cannot connect anymore due to old "Replication mode" site 0 2022-07-01 2022-07-29
Incorrect behavior in permuteDomain where domain has a trailing dot 0 2021-04-26 2022-09-07
Missing clean sensitive memory 0 2022-06-12 2022-10-05
NATS JetStream fetch from pull subscribe returns None instead of Msg object 4 2022-08-31 2022-09-25
JetStream client raises TimeoutError after reconnect 0 2022-09-18 2022-09-25
Support @deprecated in Visual Studio (2019/2022) 3 2022-04-05 2022-10-05
shadowsocks-rust faces an abnormal exit due to writing the wrong json file 3 2021-07-06 2022-10-05
Question: how can I activate Flexmark-java's attributes extension? 2 2022-06-11 2022-09-24
在使用 Controller 中的 supportedOrientationMask 属性赋值时候.然后下拉屏幕 菜单(WIFI -- 流量开关 -- 黑夜模式 那个菜单会出现横竖屏错乱) 0 2021-03-04 2022-09-17
Theme/Plugin Bundling: Data file to map plugins to stepper steps 2 2022-07-13 2022-10-05
Inconsistent results if running a limit query with a group by on a numeric dimensional field and not adding that field to order by statement post upgrade of Druid from 20.1 to .21.1 0 2021-09-29 2022-09-18
Sometimes the environment config is not loaded properly 1 2021-02-15 2022-10-05
When long press TextInput field will cut out bottom half of the screen 0 2022-07-29 2022-09-20
Not able to change bottom tabs icons and text at runtime theme change 0 2022-08-03 2022-09-20
[IOS] BottomTabItem title and icon are GONE after mergeOptions 0 2022-08-18 2022-09-20
bottomTabs+topBar with drawBehind/visible=true not working when pushing a screen with animation options 1 2022-08-17 2022-09-20