React-Native run-ios `TypeError: undefined is not an object (evaluating 'this.__callReactNativeMicrotasks')`
drizzlesconsin opened this issue · 5 comments
drizzlesconsin commented
错误
TypeError: undefined is not an object (evaluating 'this.__callReactNativeMicrotasks')
请问有没有遇到过这个问题的?
前进一步一个坑,填的差不多了,遇到了这个。
环境
System:
OS: macOS 12
CPU: (4) x64 Intel(R)
Binaries:
Node: 14.19.2
Yarn: 1.22.17
npm: 8.5.5
Managers:
CocoaPods: 1.11.3
SDKs:
iOS SDK:
Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 23, 27, 28, 29, 30, 31
Build Tools: 28.0.3, 29.0.2, 30.0.2, 33.0.0
Android NDK: Not Found
IDEs:
Android Studio: 2021.1
Xcode: 13
Languages:
Java: 1.8.0_211
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.2 => 17.0.2
react-native: ^0.67.3 => 0.67.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
操作步骤
$ taro init testApp # 1.
👽 Taro v3.4.9
# 选择 React + TypeScript + Sass + Github(最新) + react-native
$ yarn upgradePeerdeps # 2. ✅
$ yarn start # 3. ✅
- 打包这一步与官方示例显示的结果不一致。没有
transform[stdout]...
的过程,但是又没有报错。
$ yarn build:rn --platform ios
- 这一步能正常启动模拟器,但是页面空白。
$ yarn ios
5.1 为了能看到错误信息,断掉 bundle server, 再跑 yarn ios
,错误如图:
5.2 在 Xcode 打开项目,报红:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>
Error: Unable to resolve module ./index from APP_NAME/.: <br><br>
None of these files exist:<br>
* index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)<br>
* index/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)<br>
at ModuleResolver.resolveDependency (APP_NAME/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:107:15)<br>
at DependencyGraph.resolveDependency (APP_NAME/node_modules/metro/src/node-haste/DependencyGraph.js:288:43)<br>
at APP_NAME/node_modules/metro/src/lib/transformHelpers.js:129:24<br>
at Server._resolveRelativePath (APP_NAME/node_modules/metro/src/Server.js:1072:12)<br>
at async Server.requestProcessor [as _processBundleRequest] (APP_NAME/node_modules/metro/src/Server.js:428:37)<br>
at async Server._processRequest (APP_NAME/node_modules/metro/src/Server.js:380:9)</pre>
</body>
</html>
补充
- 跑壳子 taro-native-shell没问题,能成功加载显示。
- 上面的环境跑 react-native
0.68.x
新建的项目也能正常运行。 - iOS 模拟器试过
15
,14.5
- 通过 Taro Playground APP 调试也是空白,无错误信息。按 R 刷新也能看加载进度。
package.json
{ "dependencies": { "@babel/runtime": "^7.7.7", "@react-native-async-storage/async-storage": "~1.15.11", "@react-native-community/cameraroll": "~4.1.2", "@react-native-community/clipboard": "~1.5.1", "@react-native-community/geolocation": "~2.0.2", "@react-native-community/netinfo": "~7.1.2", "@react-native-community/slider": "~4.1.12", "@react-native-masked-view/masked-view": "~0.2.6", "@react-native-picker/picker": "~2.2.1", "@tarojs/components": "3.4.9", "@tarojs/plugin-framework-react": "3.4.9", "@tarojs/react": "3.4.9", "@tarojs/runtime": "3.4.9", "@tarojs/taro": "3.4.9", "@tarojs/taro-rn": "3.4.9", "expo-av": "~9.2.3", "expo-barcode-scanner": "~10.2.2", "expo-brightness": "~9.2.2", "expo-camera": "~11.2.2", "expo-file-system": "~11.1.3", "expo-image-picker": "~10.2.3", "expo-keep-awake": "~9.2.0", "expo-permissions": "~12.1.1", "expo-sensors": "~10.2.2", "react": "^17.0.2", "react-dom": "^17.0.2", "react-native": "^0.67.3", "react-native-device-info": "~8.4.8", "react-native-gesture-handler": "~1.10.3", "react-native-image-resizer": "~1.4.5", "react-native-pager-view": "~5.4.9", "react-native-safe-area-context": "~3.4.1", "react-native-screens": "^3.12.0", "react-native-svg": "~12.1.1", "react-native-syan-image-picker": "0.5.3", "react-native-unimodules": "~0.14.10", "react-native-webview": "~11.14.3" }, "devDependencies": { "@babel/core": "^7.8.0", "@tarojs/cli": "3.4.9", "@tarojs/mini-runner": "3.4.9", "@tarojs/rn-runner": "3.4.9", "@tarojs/webpack-runner": "3.4.9", "@types/react": "^17.0.2", "@types/react-native": "^0.67.0", "@types/webpack-env": "^1.13.6", "@typescript-eslint/eslint-plugin": "^5.20.0", "@typescript-eslint/parser": "^5.20.0", "babel-preset-taro": "3.4.9", "eslint": "^8.12.0", "eslint-config-taro": "3.4.9", "eslint-plugin-import": "^2.12.0", "eslint-plugin-react": "^7.8.2", "eslint-plugin-react-hooks": "^4.2.0", "install-peerdeps": "^3.0.3", "pod-install": "^0.1.23", "stylelint": "9.3.0", "typescript": "^4.1.0" } }
zhiqingchen commented
drizzlesconsin commented
5.1 根据上面的方法,能解决。
5.2 中的问题未能解决。通过 Xcode 打开 ios/xx.xcworkspace
build 失败。错误如上
zhiqingchen commented
- 避免缓存影响
yarn dev:rn --reset-cache
- 检测metro server是否正常运行
http://127.0.0.1:8081/index.bundle?platform=ios&dev=true
- xcode如果也启动了metro server,需要kill,使用1方法进行启动
drizzlesconsin commented
@zhiqingchen 感谢解答。🎉
原来 Xcode Clean Build Folder 没用,还需要清掉 Metro 打包的缓存。
手动调用打包 js bundle,再通过 Xcode Run,完美运行。
---UPDATED---
试了一下,似乎只能先手动启动 yarn dev:rn
, 再用 Xcode Run 才能正常运行。Xcode 自动打开的就会有这个问题。