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

error: SyntaxError: .../node_modules/react-native/Libraries/Components/Touchable/Touchable.js: Unexpected token, expected "]" (25:45)

Open alexkendall opened this issue 3 years ago • 26 comments

New Version

0.70.0

Old Version

0.63.3

Build Target(s)

iOS 16.0

Output of react-native info

System: OS: macOS 13.0 CPU: (8) x64 Apple M1 Memory: 27.19 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm Watchman: 2021.06.07.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/alex/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: API Levels: 28, 29, 30, 31 Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0, 31.0.0 System Images: android-25 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play ARM 64 v8a, android-31 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 4.2 AI-202.7660.26.42.7486908 Xcode: 14.0/14A309 - /usr/bin/xcodebuild Languages: Java: 11.0.10 - /opt/homebrew/opt/openjdk@11/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

Issue and Reproduction Steps

  1. Build the app using Xcode 14
  2. yarn start --reset-cache
  3. Error displays

alexkendall avatar Sep 18 '22 21:09 alexkendall

Screenshot 2022-09-19 at 8 06 07 PM

alexkendall avatar Sep 20 '22 00:09 alexkendall

+1 Same issue is happening to me

hemantgogia09 avatar Sep 20 '22 06:09 hemantgogia09

Same for Android upgrading form 0.63.4

ChaseApptentive avatar Sep 20 '22 16:09 ChaseApptentive

By the way @here. I had to patch that file using the version from 0.69 with patch-package to get the latest version of react-native to compile after upgrading from 0.63.3

alexkendall avatar Sep 20 '22 18:09 alexkendall

Just upgraded from 0.63.4 to 0.70.1 and got this error This helped me rm -fr node_modules watchman watch-del-all

bulatshafigullin avatar Sep 27 '22 10:09 bulatshafigullin

Running into this error as well, upgraded from 0.64.0 to 0.70.2

lmarques6 avatar Oct 06 '22 15:10 lmarques6

Running into this error as well, upgraded from 0.67.3 to 0.70.3

maximpostnikov avatar Oct 18 '22 23:10 maximpostnikov

Hello, solve this issue writing this in app console : rm -rf node_modules rm yarn.lock yarn

rmojsejkov avatar Oct 21 '22 00:10 rmojsejkov

Issue persists when upgrading from 0.69.3 to 0.70.4

Temporary work around react-native+0.70.4.patch

diff --git a/node_modules/react-native/Libraries/Components/Touchable/Touchable.js b/node_modules/react-native/Libraries/Components/Touchable/Touchable.js
index ea448b3..a1fb596 100644
--- a/node_modules/react-native/Libraries/Components/Touchable/Touchable.js
+++ b/node_modules/react-native/Libraries/Components/Touchable/Touchable.js
@@ -21,18 +21,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheet';
 import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
 import type {PressEvent} from '../../Types/CoreEventTypes';
 
-const extractSingleTouch = (nativeEvent: {
-  +changedTouches: $ReadOnlyArray<PressEvent['nativeEvent']>,
-  +force?: number,
-  +identifier: number,
-  +locationX: number,
-  +locationY: number,
-  +pageX: number,
-  +pageY: number,
-  +target: ?number,
-  +timestamp: number,
-  +touches: $ReadOnlyArray<PressEvent['nativeEvent']>,
-}) => {
+const extractSingleTouch = nativeEvent => {
   const touches = nativeEvent.touches;
   const changedTouches = nativeEvent.changedTouches;
   const hasTouches = touches && touches.length > 0;

dcangulo avatar Oct 27 '22 11:10 dcangulo

I also had a similar problem

xianguoGou avatar Nov 08 '22 01:11 xianguoGou

It's because babel core and runtime are out of date when you upgrade.

Even though the package.json specifies an earlier version when you start a new project from scratch it installs a newer version that works. I am sure all testing was done from scratch.

Force an update to:

"@babel/core": 7.20.5 "@babel/runtime": 7.20.6

The versions I supplied came right from the lock files of a new install and resolve the issue.

aprakimble avatar Nov 30 '22 09:11 aprakimble

This should be fixed in main by https://github.com/facebook/react-native/commit/3e19c9764634049731b4bf96dc1c716064394d62. @cortinico, might be worth picking the Babel updates into 71?

Edit: Thinking about it, the RN template dependencies shouldn’t be the immediate cause here - the syntax error is coming through Metro (whose Babel deps were bumped simultaneously), ~~so we should be ok as long as the Metro 0.73.5 release makes it into RN 0.71.~~

Edit 2: Scratch that, https://github.com/facebook/metro/commit/5f9ba404ca5510386c509cb649295810cfd87f5f didn’t make it into the last Metro release.

Edit 3: This is now fixed in Metro 0.73.6, which will be part of the next CLI release and should make it into RN 0.71.0. CC @kelset, @dmytrorykun.

robhogan avatar Dec 05 '22 12:12 robhogan

Can anyone help me solve this issue? I Mean What to do?

irfanukani avatar Dec 12 '22 14:12 irfanukani

@irfanukani Run yarn add @babel/core --dev

dcangulo avatar Dec 12 '22 15:12 dcangulo

@dcangulo I already did that.

image

irfanukani avatar Dec 12 '22 15:12 irfanukani

Can anyone help me solve this issue?

NETCHANOK61 avatar Dec 18 '22 11:12 NETCHANOK61

Update these two dev dependencies to the below versions "@babel/core": 7.20.5 "@babel/runtime": 7.20.6

Then delete your node modules and yarn install or npm install

It should start working.

gowravl avatar Dec 18 '22 12:12 gowravl

Changing package.json might not get what you want and shouldn't be necessary. The simplest thing to do, if you can, is to delete yarn.lock and node_modules and run yarn again.

robhogan avatar Dec 18 '22 12:12 robhogan

@robhogan it is a bad idea. this should be done only if package.json has fixed versions without ^

maximpostnikov avatar Dec 18 '22 14:12 maximpostnikov

Updating versions within your project's package.json will force an update to your top-level Babel but won't necessarily change the lockfile entry that locks Metro to a buggy version of Babel, so you may still get those buggy older versions nested within your node_modules - that's why that fix hasn't worked for some people in this thread.

By deleting yarn.lock, you'll allow Yarn to look up the latest versions of Babel that match Metro's dependencies (as well as your project's), which today will be 7.20.x.

The only other way to be sure of the version of a transitive dependency would be to use Yarn's package.json#resolutions, but that's more complex than necessary here (it may be useful for folks who don't want to delete the whole lockfile or manually edit it).

robhogan avatar Dec 18 '22 14:12 robhogan

Seeing this issue after upgrading to 0.70 but only when running jest tests. Running the app in simulator or on device works fine.

@babel/core: 7.20.12 @babel/runtime: 7.20.7

SyntaxError: node_modules/react-native/Libraries/Components/Touchable/Touchable.js: Unexpected token, expected "]" (25:45)

      23 |
      24 | const extractSingleTouch = (nativeEvent: {
    > 25 |   +changedTouches: $ReadOnlyArray<PressEvent['nativeEvent']>,
         |                                              ^
      26 |   +force?: number,
      27 |   +identifier: number,
      28 |   +locationX: number,

      at Object._raise (node_modules/jest-config/node_modules/@babel/parser/src/parser/error.js:60:45)

If I try to use the exact versions of babel runtime and core suggested earlier by @aprakimble, I get a different issue (Cannot find module '@babel/parser' to link)

raldred avatar Jan 05 '23 14:01 raldred

It sounds like this is probably solved in RN 0.71, but I'm on 0.70.7 and still getting issues. Adding this to my package.json solved it for me. See https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides for details of what this does.

"overrides": {
    "@react-native-community/cli": "^10.1.0"
}

bwindsor avatar Mar 02 '23 09:03 bwindsor

Upgrading from 69 up to 70 and seeing the same error, however I am not seeing it in runtime but instead when running tests.

I've gone ahead and updated both babel packages to the following:

@babel/core: 7.20.12 @babel/runtime: 7.20.7

But still seeing the issue present in tests.

@bwindsor I am going to try your solution to see if it will work in our current branch with the upgrade. Does your suggestion include clearing out the yarn.lock file to make sure the desired cli is picked up?

Coffeegerm avatar Jun 20 '23 18:06 Coffeegerm

@Coffeegerm I don't remember if I also removed the .lock file, or if just running npm install / yarn install again was sufficient. Sorry to not be of more help on that!

bwindsor avatar Jun 20 '23 19:06 bwindsor

@bwindsor Dang, neither

"overrides": {
    "@react-native-community/cli": "^10.1.0"
}

or

"overrides": {
  "react-native: {
      "@react-native-community/cli": "^10.1.0"
   }
}

have seemed to work. Not seeing any indication of the yarn.lock file getting updated for the new dependency version 😞

Has anyone else found a possible solution beyond a patch-package?

Coffeegerm avatar Jul 06 '23 20:07 Coffeegerm

ANYONE EVER SOLVE THIS ISSUE?

RyanSpeciale avatar Oct 24 '23 19:10 RyanSpeciale

working on a project that I took from RN 0.63.3 to 0.70.0 and I am now seeing this issue, I tried removing node modules and re-installing.

RyanSpeciale avatar Oct 24 '23 19:10 RyanSpeciale

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 22 '24 05:04 github-actions[bot]

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

github-actions[bot] avatar Apr 29 '24 05:04 github-actions[bot]