按照文档教程跑demo都报错
相关平台
React Native
使用框架: React
复现步骤
yarn global add @tarojs/cli select react select typescript select 预处理器无 select 默认模板 taro init myApp cd myApp yarn yarn dev:run 访问:http://127.0.0.1:8081/index.bundle?platform=ios&dev=true
期望结果
正常运行
实际结果
{
"type": "TransformError",
"lineNumber": 0,
"errors": [
{
"description": "index.js: [BABEL] E:\Job\taro\base-taro-app\index.js: Cannot find module 'metro-react-native-babel-preset'\nRequire stack:\n- E:\Job\taro\base-taro-app\node_modules\@rnx-kit\babel-preset-metro-react-native\src\index.js\n- E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\rn\index.js\n- E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\index.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\module-types.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\configuration.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\index.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\index.js\n- E:\Job\taro\base-taro-app\node_modules\metro-transform-worker\src\index.js\n- E:\Job\taro\base-taro-app\node_modules\metro\src\DeltaBundler\Worker.flow.js\n- E:\Job\taro\base-taro-app\node_modules\metro\src\DeltaBundler\Worker.js\n- E:\Job\taro\base-taro-app\node_modules\jest-worker\build\workers\processChild.js (While processing: "E:\\Job\\taro\\base-taro-app\\node_modules\\babel-preset-taro\\index.js")",
"lineNumber": 0
}
],
"name": "SyntaxError",
"message": "index.js: [BABEL] E:\Job\taro\base-taro-app\index.js: Cannot find module 'metro-react-native-babel-preset'\nRequire stack:\n- E:\Job\taro\base-taro-app\node_modules\@rnx-kit\babel-preset-metro-react-native\src\index.js\n- E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\rn\index.js\n- E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\index.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\module-types.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\configuration.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\index.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\index.js\n- E:\Job\taro\base-taro-app\node_modules\metro-transform-worker\src\index.js\n- E:\Job\taro\base-taro-app\node_modules\metro\src\DeltaBundler\Worker.flow.js\n- E:\Job\taro\base-taro-app\node_modules\metro\src\DeltaBundler\Worker.js\n- E:\Job\taro\base-taro-app\node_modules\jest-worker\build\workers\processChild.js (While processing: "E:\\Job\\taro\\base-taro-app\\node_modules\\babel-preset-taro\\index.js")",
"stack": "Error: [BABEL] E:\Job\taro\base-taro-app\index.js: Cannot find module 'metro-react-native-babel-preset'\nRequire stack:\n- E:\Job\taro\base-taro-app\node_modules\@rnx-kit\babel-preset-metro-react-native\src\index.js\n- E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\rn\index.js\n- E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\index.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\module-types.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\configuration.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\config\files\index.js\n- E:\Job\taro\base-taro-app\node_modules\@babel\core\lib\index.js\n- E:\Job\taro\base-taro-app\node_modules\metro-transform-worker\src\index.js\n- E:\Job\taro\base-taro-app\node_modules\metro\src\DeltaBundler\Worker.flow.js\n- E:\Job\taro\base-taro-app\node_modules\metro\src\DeltaBundler\Worker.js\n- E:\Job\taro\base-taro-app\node_modules\jest-worker\build\workers\processChild.js (While processing: "E:\\Job\\taro\\base-taro-app\\node_modules\\babel-preset-taro\\index.js")\n at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)\n at Function.resolve (node:internal/modules/helpers:188:19)\n at loadPreset (E:\Job\taro\base-taro-app\node_modules\@rnx-kit\babel-preset-metro-react-native\src\index.js:144:17)\n at module.exports (E:\Job\taro\base-taro-app\node_modules\@rnx-kit\babel-preset-metro-react-native\src\index.js:228:36)\n at module.exports (E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\rn\index.js:23:16)\n at apply (E:\Job\taro\base-taro-app\node_modules\babel-preset-taro\index.js:26:12)\n at sync (E:\Job\taro\base-taro-app\node_modules\@babel\core\src\gensync-utils\async.ts:31:25)\n at sync (E:\Job\taro\base-taro-app\node_modules\gensync\index.js:182:19)\n at factory (E:\Job\taro\base-taro-app\node_modules\gensync\index.js:210:24)\n at Generator.next (
环境信息
Taro CLI 4.0.6 environment info:
System:
OS: Windows 11 10.0.22631
Binaries:
Node: 18.19.1 - D:\Programs\node\node.EXE
Yarn: 1.22.22 - D:\Program Files\Nodejs\node_global\yarn.CMD
npm: 10.2.4 - D:\Programs\node\npm.CMD
npmPackages:
@tarojs/cli: 4.0.6 => 4.0.6
@tarojs/components: 4.0.6 => 4.0.6
@tarojs/components-rn: ^4.0.6 => 4.0.6
@tarojs/helper: 4.0.6 => 4.0.6
@tarojs/plugin-framework-react: 4.0.6 => 4.0.6
@tarojs/plugin-platform-alipay: 4.0.6 => 4.0.6
@tarojs/plugin-platform-h5: 4.0.6 => 4.0.6
@tarojs/plugin-platform-harmony-hybrid: 4.0.6 => 4.0.6
@tarojs/plugin-platform-jd: 4.0.6 => 4.0.6
@tarojs/plugin-platform-qq: 4.0.6 => 4.0.6
@tarojs/plugin-platform-swan: 4.0.6 => 4.0.6
@tarojs/plugin-platform-tt: 4.0.6 => 4.0.6
@tarojs/plugin-platform-weapp: 4.0.6 => 4.0.6
@tarojs/react: 4.0.6 => 4.0.6
@tarojs/rn-runner: ^4.0.6 => 4.0.6
@tarojs/rn-supporter: ^4.0.6 => 4.0.6
@tarojs/runtime: 4.0.6 => 4.0.6
@tarojs/runtime-rn: ^4.0.6 => 4.0.6
@tarojs/shared: 4.0.6 => 4.0.6
@tarojs/taro: 4.0.6 => 4.0.6
@tarojs/taro-loader: 4.0.6 => 4.0.6
@tarojs/taro-rn: ^4.0.6 => 4.0.6
@tarojs/webpack5-runner: 4.0.6 => 4.0.6
babel-preset-taro: 4.0.6 => 4.0.6
eslint-config-taro: 4.0.6 => 4.0.6
expo: ~50.0.2 => 50.0.21
react: ^18.2.0 => 18.3.1
react-native: ^0.73.1 => 0.73.10
执行后yarn add metro-react-native-babel-preset 通过Taro Playground启动报: ERROR TypeError: undefined is not a function, js engine: hermes 无法进入首页 通过分离模式启动窗口无报错应用会闪退无法进入首页
我在使用基础项目的时候也有问题 一直无法推进。
官方人员请联合查看 https://github.com/NervJS/taro/discussions/16739
我的也是,刚接触,直接按照文档做,一样的问题
https://github.com/zhiqingchen/taro-test/tree/tests/4.0.9
这里有初始化验证过编译的 demo
到处报错,没法用