react-native icon indicating copy to clipboard operation
react-native copied to clipboard

React.forwardRef(ActivityIndicator) issue

Open shijoavb opened this issue 9 months ago • 27 comments

Description

ActivityIndicator/ActivityIndicator.js: Missing initializer in const declaration. (156:41)

154 | */ 155 |

156 | const ActivityIndicatorWithRef: component( | ^ 157 | ref: React.RefSetter<HostComponent>, 158 | ...props: Props 159 | ) = React.forwardRef(ActivityIndicator);

Steps to reproduce

Npx react-native run-android

React Native Version

0.77.0

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
  OS: macOS 14.7.1
  CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Memory: 409.16 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.9.0
    path: /usr/local/bin/node
  Yarn: Not Found
  npm:
    version: 10.8.3
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.10.14.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.1
    path: /Users/shishijojacob/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK:
    API Levels:
      - "23"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 27.0.3
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-30 | Google Play Intel x86 Atom
      - android-33 | Google APIs Intel x86 Atom_64
      - android-35 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/local/bin/javac
  Ruby:
    version: 3.1.0
    path: /Users/shishijojacob/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.77.0
    wanted: ^0.77.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

/node_modules/react-native/Libraries/Components/ActivityIndicator/ActivityIndicator.js: Missing initializer in const declaration. (156:41)

  154 | */
  155 |
> 156 | const ActivityIndicatorWithRef: component(
      |                                          ^
  157 |   ref: React.RefSetter<HostComponent<empty>>,
  158 |   ...props: Props
  159 | ) = React.forwardRef(ActivityIndicator);
 BUNDLE  ./index.js

Reproducer

https://github.com/

Screenshots and Videos

No response

shijoavb avatar Jan 30 '25 07:01 shijoavb

[!WARNING] Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

react-native-bot avatar Jan 30 '25 07:01 react-native-bot

is there any solution?

karamanmertcan avatar Jan 30 '25 12:01 karamanmertcan

Hey @shijoavb, I couldn't reproduce the issue in my repository.

Please attach a repository or the code to reproduce the same.

migueldaipre avatar Jan 30 '25 14:01 migueldaipre

I also encountered the same issues.

Image

I resolved them by updating the npm package versions, setting them based on the reference from this project (npx @react-native-community/cli@latest init AwesomeProject).

Image

Specifically, I updated the following packages: • @babel/core • @babel/preset-env • @babel/runtime • @react-native-community/cli • @react-native-community/cli-platform-android • @react-native-community/cli-platform-ios • @react-native/babel-preset • @types/react • eslint • jest • prettier • typescript

Hope it helps you

"name": "AwesomeProject",
      "version": "0.0.1",
      "dependencies": {
        "react": "18.3.1",
        "react-native": "0.77.0"
      },
      "devDependencies": {
        "@babel/core": "^7.25.2",
        "@babel/preset-env": "^7.25.3",
        "@babel/runtime": "^7.25.0",
        "@react-native-community/cli": "15.0.1",
        "@react-native-community/cli-platform-android": "15.0.1",
        "@react-native-community/cli-platform-ios": "15.0.1",
        "@react-native/babel-preset": "0.77.0",
        "@react-native/eslint-config": "0.77.0",
        "@react-native/metro-config": "0.77.0",
        "@react-native/typescript-config": "0.77.0",
        "@types/jest": "^29.5.13",
        "@types/react": "^18.2.6",
        "@types/react-test-renderer": "^18.0.0",
        "eslint": "^8.19.0",
        "jest": "^29.6.3",
        "prettier": "2.8.8",
        "react-test-renderer": "18.3.1",
        "typescript": "5.0.4"
      },
      "engines": {
        "node": ">=18"
      }

ShawnBaek avatar Feb 01 '25 15:02 ShawnBaek

Same problem here, there are many problems of "Missing initializer in const declaration" in many files, not only ActivityIndicator.js (Button.js, SafeAreaView, Switch, InteractionManager...)

Please bring some fix on this

Houdhey avatar Feb 01 '25 21:02 Houdhey

Facing same problem

alihamza1729 avatar Feb 03 '25 11:02 alihamza1729

/react-native/Libraries/Components/ActivityIndicator/ActivityIndicator.js: Missing initializer in const declaration. (156:41)

  154 | */
  155 |
> 156 | const ActivityIndicatorWithRef: component(

still facing same issue

CMLCNL avatar Feb 03 '25 19:02 CMLCNL

same here ERROR SyntaxError: /Users/artyomkalantay/WebstormProjects/Paw/node_modules/react-native/Libraries/Components/ActivityIndicator/ActivityIndicator.js: Missing initializer in const declaration. (156:41)

154 | */ 155 |

156 | const ActivityIndicatorWithRef: component( | ^ 157 | ref: React.RefSetter<HostComponent>, 158 | ...props: Props 159 | ) = React.forwardRef(ActivityIndicator);

Shmublon avatar Feb 03 '25 23:02 Shmublon

error SyntaxError: /node_modules/react-native/Libraries/Components/ScrollView/ScrollView.js: Unexpected token, expected "=>" (372:1)

370 | ref?: React.RefSetter<$ReadOnly<{ setNextHeaderY: (number) => void }>>, 371 | ...ScrollViewStickyHeaderProps

372 | ); | ^ 373 370 | ref?: React.RefSetter<$ReadOnly<{ setNextHeaderY: (number) => void }>>, 371 | ...ScrollViewStickyHeaderProps 372 | );

Task :app:createBundleReleaseJsAndAssets FAILED

FAILURE: Build failed with an exception.

prashilak avatar Feb 03 '25 23:02 prashilak

Facing same problem here

pimich0 avatar Feb 04 '25 04:02 pimich0

I have fixed it by adding presets: ['module:@react-native/babel-preset'], this in place of presets: ['module:metro-react-native-babel-preset'] in babel.config.js they have removed metro-react-native-babel-preset

alihamza1729 avatar Feb 04 '25 05:02 alihamza1729

I have fixed it by adding presets: ['module:@react-native/babel-preset'], this in place of presets: ['module:metro-react-native-babel-preset'] in babel.config.js they have removed metro-react-native-babel-preset

I have that already set. Still have the issue

nielsq avatar Feb 04 '25 07:02 nielsq

I have fixed it by adding presets: ['module:@react-native/babel-preset'], this in place of presets: ['module:metro-react-native-babel-preset'] in babel.config.js they have removed metro-react-native-babel-preset

I have that already set. Still have the issue your package.json devDependencies should be like this "devDependencies": { "@babel/core": "^7.26.7", "@babel/preset-env": "^7.26.7", "@babel/runtime": "^7.26.7", "@react-native-community/cli": "15.1.3", "@react-native-community/cli-platform-android": "15.1.3", "@react-native-community/cli-platform-ios": "15.1.3", "@react-native/babel-preset": "0.77.0", "@react-native/eslint-config": "0.77.0", "@react-native/metro-config": "0.77.0", "@react-native/typescript-config": "0.77.0", "@types/jest": "^29.5.14", "@types/react": "^19.0.8", "@types/react-test-renderer": "^19.0.0", "eslint": "^9.19.0", "jest": "^29.7.0", "prettier": "3.4.2", "react-test-renderer": "19.0.0", "typescript": "5.7.3" }, delete node module reset cache and then start

alihamza1729 avatar Feb 04 '25 07:02 alihamza1729

For me the issue was the package "@react-native/babel-preset" I did not updated it.

nielsq avatar Feb 04 '25 12:02 nielsq

I have fixed it by adding presets: ['module:@react-native/babel-preset'], this in place of presets: ['module:metro-react-native-babel-preset'] in babel.config.js they have removed metro-react-native-babel-preset

I have that already set. Still have the issue

do u have your package.json devDependencies should be like this "devDependencies": { "@babel/core": "^7.26.7", "@babel/preset-env": "^7.26.7", "@babel/runtime": "^7.26.7", "@react-native-community/cli": "15.1.3", "@react-native-community/cli-platform-android": "15.1.3", "@react-native-community/cli-platform-ios": "15.1.3", "@react-native/babel-preset": "0.77.0", "@react-native/eslint-config": "0.77.0", "@react-native/metro-config": "0.77.0", "@react-native/typescript-config": "0.77.0", "@types/jest": "^29.5.14", "@types/react": "^19.0.8", "@types/react-test-renderer": "^19.0.0", "eslint": "^9.19.0", "jest": "^29.7.0", "prettier": "3.4.2", "react-test-renderer": "19.0.0", "typescript": "5.7.3" }, delete node module reset cache and then start

Your solution works! I have:

node -v: v22.13.1 npm -v: v11.1.0

babel.config.js

module.exports = function getBabelConfig(api) {
  api.cache(true)

  const plugins = []

  return {
    presets: ['module:@react-native/babel-preset'],
    plugins,
  }
}

package.json

...
"dependencies": {
    ...
    "react-native": "0.77.0",
    ...
  },
  "devDependencies": {
    "@babel/core": "^7.26.7",
    "@babel/preset-env": "^7.26.7",
    "@babel/runtime": "^7.26.7",
    "@react-native-community/cli": "15.1.3",
    "@react-native-community/cli-platform-android": "15.1.3",
    "@react-native-community/cli-platform-ios": "15.1.3",
    "@react-native/babel-preset": "0.77.0",
    "@react-native/eslint-config": "0.77.0",
    "@react-native/metro-config": "0.77.0",
    "@react-native/typescript-config": "0.77.0",
    "@types/jest": "^29.5.14",
    "@types/react": "^19.0.8",
    "@types/react-test-renderer": "^19.0.0",
    "eslint": "^9.19.0",
    "jest": "^29.7.0",
    "react-test-renderer": "19.0.0",
    "typescript": "5.7.3"
  },
...

I did these commands:

npm cache clean --force
rm -rf node_modules package-lock.json
npm install

vdzeer avatar Feb 04 '25 12:02 vdzeer

I have fixed it by adding presets: ['module:@react-native/babel-preset'], this in place of presets: ['module:metro-react-native-babel-preset'] in babel.config.js they have removed metro-react-native-babel-preset

I have that already set. Still have the issue

do u have your package.json devDependencies should be like this "devDependencies": { "@babel/core": "^7.26.7", "@babel/preset-env": "^7.26.7", "@babel/runtime": "^7.26.7", "@react-native-community/cli": "15.1.3", "@react-native-community/cli-platform-android": "15.1.3", "@react-native-community/cli-platform-ios": "15.1.3", "@react-native/babel-preset": "0.77.0", "@react-native/eslint-config": "0.77.0", "@react-native/metro-config": "0.77.0", "@react-native/typescript-config": "0.77.0", "@types/jest": "^29.5.14", "@types/react": "^19.0.8", "@types/react-test-renderer": "^19.0.0", "eslint": "^9.19.0", "jest": "^29.7.0", "prettier": "3.4.2", "react-test-renderer": "19.0.0", "typescript": "5.7.3" }, delete node module reset cache and then start

Your solution works! I have:

node -v: v22.13.1 npm -v: v11.1.0

babel.config.js

module.exports = function getBabelConfig(api) { api.cache(true)

const plugins = []

return { presets: ['module:@react-native/babel-preset'], plugins, } } package.json

... "dependencies": { ... "react-native": "0.77.0", ... }, "devDependencies": { "@babel/core": "^7.26.7", "@babel/preset-env": "^7.26.7", "@babel/runtime": "^7.26.7", "@react-native-community/cli": "15.1.3", "@react-native-community/cli-platform-android": "15.1.3", "@react-native-community/cli-platform-ios": "15.1.3", "@react-native/babel-preset": "0.77.0", "@react-native/eslint-config": "0.77.0", "@react-native/metro-config": "0.77.0", "@react-native/typescript-config": "0.77.0", "@types/jest": "^29.5.14", "@types/react": "^19.0.8", "@types/react-test-renderer": "^19.0.0", "eslint": "^9.19.0", "jest": "^29.7.0", "react-test-renderer": "19.0.0", "typescript": "5.7.3" }, ... I did these commands:

npm cache clean --force rm -rf node_modules package-lock.json npm install

Works for me

Hariprasanth-HP avatar Feb 16 '25 04:02 Hariprasanth-HP

Just to be clear, the solution is to add "module:@react-native/babel-preset" to your babel.config.js:

module.exports = function (api) {
...
  return {
   presets: [
      ...
      "module:@react-native/babel-preset",
      ...
    ],
   ...
  };
};

shawnlauzon avatar Feb 17 '25 14:02 shawnlauzon

for me also has the same problem

Naveenkumar-1411 avatar Feb 23 '25 16:02 Naveenkumar-1411

I'm facing exact same issue after upgrading from React Native 0.76.x to 0.78. Before this, I encountered the error More than one plugin attempted to override parsing, caused by babel-plugin-syntax-hermes-parser, which I resolved by adding a custom resolution to disable the plugin.

However, now I'm getting the exact same error related to this issue:

SyntaxError: /path/to/ActivityIndicator.js: Missing initializer in const declaration. (156:41) 154 | */ 155 |

156 | const ActivityIndicatorWithRef: component( | ^ 157 | ref: React.RefSetter<HostComponent>, 158 | ...props: Props 159 | ) = React.forwardRef(ActivityIndicator);

All dependencies appear to be correctly versioned, but I'm still encountering this issue. Any suggestions on what might be going wrong?

bekatd avatar Feb 25 '25 10:02 bekatd

'module:@react-native/babel-preset'

This fixes the issue for me, make sure to clean the caches before you start metro and build

jayantamadhav avatar Feb 26 '25 04:02 jayantamadhav

@jayantamadhav I already use @react-native/babel-preset. I've tried clearing caches, verifying versions, and other common fixes, but no luck so far.

bekatd avatar Feb 26 '25 11:02 bekatd

@bekatd did you resolve the issue?

blolo avatar Mar 09 '25 00:03 blolo

@blolo Yes, I resolved it. In my case (strangely enough), I had a Babel config imported into babel.config.json from a third-party lib we developed. For some reason, the paths weren’t resolved correctly. I fixed it by moving the Babel config from the lib into a local babel.config.js, and everything worked smoothly after that.

bekatd avatar Mar 11 '25 08:03 bekatd

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Apr 05 '25 05:04 react-native-bot

After a lot of head scratching npm cache clean --force did the trick for me. Thank you @vdzeer

cvincentcoleman avatar Apr 10 '25 17:04 cvincentcoleman

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar May 05 '25 05:05 react-native-bot

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar May 29 '25 05:05 react-native-bot

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Jun 22 '25 05:06 react-native-bot

This issue was closed because the author hasn't provided the requested feedback after 7 days.

react-native-bot avatar Jun 29 '25 05:06 react-native-bot

This issue was closed because it has been stalled for 7 days with no activity.

react-native-bot avatar Jun 29 '25 05:06 react-native-bot