react-native bundle 脚本在 typescript 模块 react-navigation 上抛出语法错误
Posted
技术标签:
【中文标题】react-native bundle 脚本在 typescript 模块 react-navigation 上抛出语法错误【英文标题】:react-native bundle script throwing syntax error on typescript module react-navigation 【发布时间】:2021-01-26 21:46:51 【问题描述】:使用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.lock
和 node_modules
用yarn cache clean
清理缓存
使用cd android ./gradlew clean
清理干净
重新安装模块
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
但是,此错误仍然存在。有什么想法吗?
【问题讨论】:
【参考方案1】:我有同样的错误。 我认为你有依赖问题。
试试:npm update
。
【讨论】:
以上是关于react-native bundle 脚本在 typescript 模块 react-navigation 上抛出语法错误的主要内容,如果未能解决你的问题,请参考以下文章
react-native metro bundle卡住并且没有运行进度条
未计算文件的 React-Native Bundle Error 错误 SHA-1
Metro server (run ‘react-native start‘) or that your bundle ‘index.android.bundle‘ is packaged corre
Metro server (run ‘react-native start‘) or that your bundle ‘index.android.bundle‘ is packaged corre
Metro server (run ‘react-native start‘) or that your bundle ‘index.android.bundle‘ is packaged corre
Metro server (run ‘react-native start‘) or that your bundle ‘index.android.bundle‘ is packaged corre