簡體   English   中英

反應原生捆綁腳本在打字稿模塊上拋出語法錯誤反應導航

[英]react-native bundle script throwing syntax error on typescript module react-navigation

使用react-native bundle腳本運行構建時,會在引用 typescript 的 react-navigation 模塊上引發錯誤。

我正在運行以下腳本以將資產構建到特定文件夾中:

react-native bundle --reset-cache --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

以下錯誤是

error SyntaxError: /Users/sachinkaria/Desktop/chemistri/qem-native-test-build/node_modules/@react-navigation/stack/src/index.tsx: Unexpected token (51:12)

  49 |  * Types
  50 |  */
> 51 | export type {
     |             ^
  52 |   StackNavigationOptions,
  53 |   StackNavigationProp,
  54 |   StackScreenProps,. Run CLI with --verbose flag for more details.
SyntaxError: /Users/sachinkaria/Desktop/chemistri/qem-native-test-build/node_modules/@react-navigation/stack/src/index.tsx: Unexpected token (51:12)

  49 |  * Types
  50 |  */
> 51 | export type {
     |             ^
  52 |   StackNavigationOptions,
  53 |   StackNavigationProp,
  54 |   StackScreenProps,
    at Object.raise (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:6400:17)
    at Object.unexpected (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:7728:16)
    at Object.parseIdentifierName (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:9624:18)
    at Object.parseIdentifier (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:9598:23)
    at Object.tsParseTypeAliasDeclaration (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:4793:20)
    at Object.tsParseDeclaration (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5111:23)
    at Object.tsTryParseExportDeclaration (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5020:17)
    at Object.parseExportDeclaration (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5497:26)
    at Object.maybeParseExportDeclaration (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:11070:31)
    at Object.parseExport (/Users/sachinkaria/.config/yarn/global/node_modules/@babel/parser/lib/index.js:10999:29)

我的 package.json 如下:

{
  "name": "Example",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "update:pods": "cd ios && pod install --repo-update && cd ..",
    "postinstall": "yarn run update:pods"
  },
  "dependencies": {
    "@expo/react-native-action-sheet": "^3.8.0",
    "@notifee/react-native": "^0.9.1",
    "@ptomasroos/react-native-multi-slider": "^2.2.2",
    "@react-native-community/async-storage": "^1.11.0",
    "@react-native-community/checkbox": "^0.4.2",
    "@react-native-community/clipboard": "^1.2.3",
    "@react-native-community/datetimepicker": "^2.6.1",
    "@react-native-community/image-editor": "^2.3.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^5.9.5",
    "@react-native-community/slider": "^3.0.3",
    "@react-native-community/toolbar-android": "0.1.0-rc.2",
    "@react-native-community/viewpager": "^4.1.3",
    "@react-native-firebase/app": "^8.4.1",
    "@react-native-firebase/auth": "^8.0.9",
    "@react-native-firebase/firestore": "^7.2.3",
    "@react-native-firebase/messaging": "^7.2.1",
    "@react-native-firebase/remote-config": "^9.0.2",
    "@react-native-firebase/storage": "^7.1.7",
    "@react-navigation/bottom-tabs": "^5.6.1",
    "@react-navigation/native": "^5.2.6",
    "@react-navigation/stack": "^5.3.1",
    "@storybook/react-native": "^5.3.19",
    "add": "^2.0.6",
    "apisauce": "^1.1.1",
    "base-64": "^0.1.0",
    "compare-versions": "^3.6.0",
    "expo-asset": "^8.1.7",
    "expo-av": "^8.2.1",
    "expo-constants": "^9.1.1",
    "expo-file-system": "^9.0.1",
    "expo-font": "^8.2.1",
    "expo-image-manipulator": "^8.2.1",
    "expo-image-picker": "^8.3.0",
    "expo-location": "^8.2.1",
    "expo-permissions": "^9.0.1",
    "formik": "^2.1.4",
    "i": "^0.3.6",
    "lodash": "^4.17.15",
    "moment": "^2.27.0",
    "native-base": "^2.13.12",
    "ngeohash": "^0.6.3",
    "npm": "^6.14.5",
    "prop-types": "^15.7.2",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-animatable": "^1.3.3",
    "react-native-calendars": "^1.300.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-device-info": "^6.0.0",
    "react-native-dotenv": "^0.2.0",
    "react-native-easy-grid": "^0.2.2",
    "react-native-fbsdk": "^2.0.0",
    "react-native-geocoding": "^0.4.0",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-gifted-chat": "^0.16.3",
    "react-native-keyboard-aware-scroll-view": "^0.9.1",
    "react-native-maps": "^0.27.1",
    "react-native-mixpanel": "^1.2.0",
    "react-native-modal": "^11.5.6",
    "react-native-permissions": "^2.1.5",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.9.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^12.1.0",
    "react-native-swiper": "^1.6.0",
    "react-native-unimodules": "^0.10.1",
    "react-native-vector-icons": "^6.6.0",
    "react-native-view-overflow": "^0.0.5",
    "yup": "^0.29.1"
  },
  "devDependencies": {
    "@babel/core": "7.9.6",
    "@babel/runtime": "7.9.6",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.8.0",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "react-test-renderer": "16.11.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

我嘗試了以下方法:

  • 刪除yarn.locknode_modules
  • 使用yarn cache clean
  • 使用cd android ./gradlew clean Gradle
  • 重新安裝模塊
  • react-native bundle --reset-cache --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

但是,此錯誤仍然存​​在。 有任何想法嗎?

我有同樣的錯誤。 我認為您有依賴性問題。

嘗試: npm update

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM