NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.6k stars 4.8k forks source link

RN: Cannot read properties of undefined (reading 'addHelper') #14100

Closed SidneyLann closed 1 week ago

SidneyLann commented 1 year ago

相关平台

React Native

复现仓库

https://github.com/SidneyLann/taro-test-repo.git

使用框架: React

复现步骤

  1. yarn
  2. yarn run dev:weapp //编译成功并且可以在开发者工具正常访问
  3. yarn android //编译通过
  4. yarn build:rn --reset-cache --platform android //编译失败, 报错: Cannot read properties of undefined (reading 'addHelper')

期望结果

在RN下能编译通过

实际结果

在RN下编译不通过

环境信息

 Taro CLI 3.6.8 environment info:
    System:
      OS: Windows 10 10.0.22621
    Binaries:
      Node: 20.3.1 - D:\DEV\nodejs\node.EXE
      Yarn: 1.22.19 - D:\DEV\nodejs\yarn.CMD
      npm: 9.6.7 - D:\DEV\nodejs\npm.CMD
    npmPackages:
      @tarojs/components: 3.6.8 => 3.6.8
      @tarojs/helper: 3.6.8 => 3.6.8
      @tarojs/plugin-framework-react: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-alipay: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-h5: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-jd: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-qq: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-swan: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-tt: 3.6.8 => 3.6.8
      @tarojs/plugin-platform-weapp: 3.6.8 => 3.6.8
      @tarojs/react: 3.6.8 => 3.6.8
      @tarojs/rn-runner: 3.6.8 => 3.6.8
      @tarojs/rn-supporter: 3.6.8 => 3.6.8
      @tarojs/runtime: 3.6.8 => 3.6.8
      @tarojs/runtime-rn: 3.6.8 => 3.6.8
      @tarojs/shared: 3.6.8 => 3.6.8
      @tarojs/taro: 3.6.8 => 3.6.8
      @tarojs/taro-rn: 3.6.8 => 3.6.8
      @tarojs/webpack5-runner: 3.6.8 => 3.6.8
      babel-preset-taro: 3.6.8 => 3.6.8
      eslint-config-taro: 3.6.8 => 3.6.8
      expo: ~47.0.3 => 47.0.14
      react: 18.1.0 => 18.1.0
      react-native: ^0.70.1 => 0.70.10
SidneyLann commented 1 year ago

3.6.11还是有这个问题. 一个多月了也没人看看吗?

SidneyLann commented 1 year ago

?

zhiqingchen commented 1 year ago

Cannot read properties of undefined (reading 'addHelper') 有详细报错信息吗

zhiqingchen commented 1 year ago

https://github.com/zhiqingchen/taro-test/tree/tests/3.6.13

3.6.13 正常编译

https://github.com/zhiqingchen/taro-test/actions

SidneyLann commented 1 year ago

D:\DEV\eb_app>yarn build:rn --reset-cache --platform android yarn run v1.22.19 $ taro build --type rn --reset-cache --platform android 👽 Taro v3.6.13

warning: the transform cache was reset. Welcome to Metro v0.72.4 Fast - Scalable - Integrated

error src\view\LegenImage.tsx: D:\DEV\eb_app\src\view\LegenImage.tsx: Cannot read properties of undefined (reading 'addHelper'). TypeError: D:\DEV\eb_app\src\view\LegenImage.tsx: Cannot read properties of undefined (reading 'addHelper') at wrapInterop (D:\DEV\eb_app\node_modules\@babel\helper-module-transforms\src\index.ts:198:41) at PluginPass.call (D:\DEV\eb_app\node_modules\@babel\plugin-transform-modules-commonjs\src\index.ts:255:28) at call (D:\DEV\eb_app\node_modules\@babel\traverse\src\visitors.ts:270:14) at NodePath._call (D:\DEV\eb_app\node_modules\@babel\traverse\src\path\context.ts:35:20) at NodePath.call (D:\DEV\eb_app\node_modules\@babel\traverse\src\path\context.ts:20:17) at NodePath.visit (D:\DEV\eb_app\node_modules\@babel\traverse\src\path\context.ts:112:8) at TraversalContext.visitQueue (D:\DEV\eb_app\node_modules\@babel\traverse\src\context.ts:144:16) at TraversalContext.visitSingle (D:\DEV\eb_app\node_modules\@babel\traverse\src\context.ts:108:19) at TraversalContext.visit (D:\DEV\eb_app\node_modules\@babel\traverse\src\context.ts:176:19) at traverseNode (D:\DEV\eb_app\node_modules\@babel\traverse\src\traverse-node.ts:34:17) at traverse (D:\DEV\eb_app\node_modules\@babel\traverse\src\index.ts:75:15) at transformFile (D:\DEV\eb_app\node_modules\@babel\core\src\transformation\index.ts:120:13) at transformFile.next () at run (D:\DEV\eb_app\node_modules\@babel\core\src\transformation\index.ts:47:12) at run.next () at D:\DEV\eb_app\node_modules\@babel\core\src\transform-ast.ts:34:20 at Generator.next () at evaluateSync (D:\DEV\eb_app\node_modules\gensync\index.js:251:28) at fn (D:\DEV\eb_app\node_modules\gensync\index.js:89:14) at stopHiding - secret - don't use this - v1 (D:\DEV\eb_app\node_modules\@babel\core\src\errors\rewrite-stack-trace.ts:97:14) at transformFromAstSync (D:\DEV\eb_app\node_modules\@babel\core\src\transform-ast.ts:77:59) at Object.transform [as nextTransformer] (D:\DEV\eb_app\node_modules\metro-react-native-babel-transformer\src\index.js:199:20) at Object.transform (D:\DEV\eb_app\node_modules\@tarojs\rn-transformer\src\index.ts:44:18) at D:\DEV\eb_app\node_modules\@tarojs\rn-supporter\src\taroTransformer.ts:59:51 at Generator.next () info Run CLI with --verbose flag for more details. Done in 170.60s.

SidneyLann commented 1 year ago

3.6.13还是一样的错误. 能拉我的复现项目编译下吗? 是不是用了linaria的原因?

SidneyLann commented 1 year ago

从新init项目还是有这个问题!

SidneyLann commented 1 year ago

module.exports = { presets: [ ['taro', { framework: 'react', ts: true, hot: false, }], '@linaria', ], }

去掉'@linaria',就可以, 加上又不行!

SidneyLann commented 1 year ago

7月2号的问题, 现在还不跑我的demo一下?

SidneyLann commented 1 year ago

引用linaria的编译问题3个多月了没人试一下, taro是要凉了吗? 都用arkui-x了吗?

SidneyLann commented 1 year ago

webpack5+linaria的编译问题能不能解决?

SidneyLann commented 1 year ago

https://github.com/babel/babel/issues/15752#issuecomment-1774807122

这里说metro升级到0.72.5就可以了, 为什么taro要把metro写死为0.72.4?

SidneyLann commented 1 year ago

不打算解决这个问题了吗?4个多月了都没人执行以下我的DEMO!

zhiqingchen commented 1 year ago

babel/babel#15752 (comment)

这里说metro升级到0.72.5就可以了, 为什么taro要把metro写死为0.72.4?

https://github.com/NervJS/taro/blob/next/packages/taro-rn-supporter/package.json#L47 这里用的是 ^0.72.1

SidneyLann commented 1 year ago

到底是什么原因编译不了嘛?

SidneyLann commented 1 year ago

升级到TARO 3.7也不行, TARO 3.7用的是metro 0.76

zhiqingchen commented 1 year ago

yarn why metro

SidneyLann commented 1 year ago

After run yarn, too many metro packages in node_modules. I don't know what metro work for, but please fix this issue.

SidneyLann commented 1 year ago

yarn run v1.22.19 $ taro build --type rn --reset-cache --platform android 👽 Taro v3.7.0-canary.1

warning: the transform cache was reset. Welcome to Metro v0.76.8 Fast - Scalable - Integrated

error node_modules\@tarojs\rn-supporter\entry-file.js: D:\prj--taro\node_modules\@tarojs\rn-supporter\entry-file.js: Cannot read properties of undefined (reading 'addHelper'). TypeError: D:\prj--taro\node_modules\@tarojs\rn-supporter\entry-file.js: Cannot read properties of undefined (reading 'addHelper') at wrapInterop (D:\prj--taro\node_modules\@babel\helper-module-transforms\src\index.ts:198:41) at PluginPass.call (D:\prj--taro\node_modules\@babel\plugin-transform-modules-commonjs\src\index.ts:255:28) at call (D:\prj--taro\node_modules\@babel\traverse\src\visitors.ts:292:14) at NodePath._call (D:\prj--taro\node_modules\@babel\traverse\src\path\context.ts:35:20) at NodePath.call (D:\prj--taro\node_modules\@babel\traverse\src\path\context.ts:20:17) at NodePath.visit (D:\prj--taro\node_modules\@babel\traverse\src\path\context.ts:112:8) at TraversalContext.visitQueue (D:\prj--taro\node_modules\@babel\traverse\src\context.ts:144:16) at TraversalContext.visitSingle (D:\prj--taro\node_modules\@babel\traverse\src\context.ts:108:19) at TraversalContext.visit (D:\prj--taro\node_modules\@babel\traverse\src\context.ts:176:19) at traverseNode (D:\prj--taro\node_modules\@babel\traverse\src\traverse-node.ts:40:17) at traverse (D:\prj--taro\node_modules\@babel\traverse\src\index.ts:82:15) at transformFile (D:\prj--taro\node_modules\@tarojs\rn-supporter\node_modules\metro-react-native-babel-transformer\node_modules\@babel\core\src\transformation\index.ts:124:15) at transformFile.next () at run (D:\prj--taro\node_modules\@tarojs\rn-supporter\node_modules\metro-react-native-babel-transformer\node_modules\@babel\core\src\transformation\index.ts:48:12) at run.next () at D:\prj--taro\node_modules\@tarojs\rn-supporter\node_modules\metro-react-native-babel-transformer\node_modules\@babel\core\src\transform-ast.ts:34:20 at Generator.next () at evaluateSync (D:\prj--taro\node_modules\gensync\index.js:251:28) at fn (D:\prj--taro\node_modules\gensync\index.js:89:14) at stopHiding - secret - don't use this - v1 (D:\prj--taro\node_modules\@tarojs\rn-supporter\node_modules\metro-react-native-babel-transformer\node_modules\@babel\core\src\errors\rewrite-stack-trace.ts:99:14) at transformFromAstSync (D:\prj--taro\node_modules\@tarojs\rn-supporter\node_modules\metro-react-native-babel-transformer\node_modules\@babel\core\src\transform-ast.ts:77:59) at Object.transform [as nextTransformer] (D:\prj--taro\node_modules\@tarojs\rn-supporter\node_modules\metro-react-native-babel-transformer\src\index.js:201:20) at Object.transform (D:\prj--taro\node_modules\@tarojs\rn-transformer\src\index.ts:44:18) at transform (D:\prj--taro\node_modules\@tarojs\rn-supporter\src\taroTransformer.ts:63:51) at Object.module.exports.transform (D:\prj--taro\node_modules\@tarojs\rn-supporter\src\taroTransformer.ts:75:10) at transformJSWithBabel (D:\prj--taro\node_modules\metro-transform-worker\src\index.js:399:45) at Object.transform (D:\prj--taro\node_modules\metro-transform-worker\src\index.js:572:18) at transformFile (D:\prj--taro\node_modules\metro\src\DeltaBundler\Worker.flow.js:82:36) at Object.transform (D:\prj--taro\node_modules\metro\src\DeltaBundler\Worker.flow.js:55:10) at WorkerFarm.transform (D:\prj--taro\node_modules\metro\src\DeltaBundler\WorkerFarm.js:55:39) at Transformer.transformFile (D:\prj--taro\node_modules\metro\src\DeltaBundler\Transformer.js:130:32) at Object.transform (D:\prj--taro\node_modules\metro\src\lib\transformHelpers.js:136:12) at processModule (D:\prj--taro\node_modules\metro\src\DeltaBundler\graphOperations.js:229:18) at addDependency (D:\prj--taro\node_modules\metro\src\DeltaBundler\graphOperations.js:361:18) at async Promise.all (index 0) at processModule (D:\prj--taro\node_modules\metro\src\DeltaBundler\graphOperations.js:279:3) at traverseDependenciesForSingleFile (D:\prj--taro\node_modules\metro\src\DeltaBundler\graphOperations.js:221:3) at async Promise.all (index 0) at initialTraverseDependencies (D:\prj--taro\node_modules\metro\src\DeltaBundler\graphOperations.js:204:3) at DeltaCalculator._getChangedDependencies (D:\prj--taro\node_modules\metro\src\DeltaBundler\DeltaCalculator.js:208:25) at DeltaCalculator.getDelta (D:\prj--taro\node_modules\metro\src\DeltaBundler\DeltaCalculator.js:90:16) at DeltaBundler.buildGraph (D:\prj--taro\node_modules\metro\src\DeltaBundler.js:56:5) at IncrementalBundler.buildGraphForEntries (D:\prj--taro\node_modules\metro\src\IncrementalBundler.js:81:19) at IncrementalBundler.buildGraph (D:\prj--taro\node_modules\metro\src\IncrementalBundler.js:161:19) at Server.build (D:\prj--taro\node_modules\metro\src\Server.js:142:32) at buildBundleWithConfig (D:\prj--taro\node_modules\@react-native-community\cli-plugin-metro\src\commands\bundle\buildBundle.ts:110:20) info Run CLI with --verbose flag for more details. Done in 402.33s.

SidneyLann commented 1 year ago

Run my demo and should get this error.

SidneyLann commented 1 year ago

Or give me a workaround, thanks.

SidneyLann commented 1 year ago

https://github.com/babel/babel/issues/16094#issuecomment-1806670063 babel官方说这个插件babel-plugin-minify-dead-code-elimination引起的,这个插件已经两年不维护了,建议移除。@zhiqingchen

SidneyLann commented 1 year ago

把这个插件去掉就可以编译了!从6月份卡到现在!

zhiqingchen commented 1 year ago

感谢,可以先在这个文件中 node_modules/babel-preset-taro/rn/index.js 注释一下。

SidneyLann commented 1 year ago

我去掉了,跑起来了。下个版本记得去掉吧。

wiilsliang commented 7 months ago

感谢,可以先在这个文件中 node_modules/babel-preset-taro/rn/index.js 注释一下。

@zhiqingchen 都taro v2.3.26版本还只能注销吗,到现在还没处理这个问题?

SidneyLann commented 1 month ago

// plugins.push( // [require('babel-plugin-minify-dead-code-elimination'), {}] // )

搞什么飞机,4.0.6这个还是没有注释掉!

感觉现在没人在维护TARO了,现有的微信群没任何人回答问题,全是群员发的广告,新群也不再接受加入!

SidneyLann commented 3 weeks ago

@zhiqingchen 老大,不在58了吗?这个怎么还不删掉?每次跑yarn都要改一次! \node_modules\babel-preset-taro\rn\index.js // plugins.push( // [require('babel-plugin-minify-dead-code-elimination'), {}] // )