NervJS / taro

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

3.5.7 版本 react框架 字节小程序 使用 lodash 的 cloneDeep 函数异常 #12720

Open Rlagnl opened 1 year ago

Rlagnl commented 1 year ago

相关平台

字节跳动小程序

小程序基础库: 任何 使用框架: React

复现步骤

https://github.com/Rlagnl/taro-3.5.7-react-tt-lodash/tree/20221027

期望结果

字节小程序正常运行

实际结果

有 js error tma-core.js:2 [TMA] TypeError: Cannot read property 'prototype' of undefined at runInContext2 (vendors-node_modules_taro_tt_prebundle_lodash_js.js:802) at Object.<anonymous> (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5579) at node_modules/lodash/lodash.js (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5586) at __require (node_modules_taro_tt_prebundle_react_js.js:27) at entry:lodash (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5592) at __require (node_modules_taro_tt_prebundle_react_js.js:27) at Object../node_modules/.taro/tt/prebundle/lodash.core.js (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5595) at __webpack_require__ (bootstrap:19) at Object../node_modules/.taro/tt/prebundle/lodash.js (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5613) at __webpack_require__ (bootstrap:19) (anonymous) @ tma-core.js:2 (anonymous) @ tma-core.js:2 Yi.emit @ tma-core.js:2 ps @ tma-core.js:2 n @ tma-core.js:2 (anonymous) @ app-service.js:98 tma-core.js:2 Uncaught TypeError: Cannot read property 'prototype' of undefined at runInContext2 (vendors-node_modules_taro_tt_prebundle_lodash_js.js:802) at Object.<anonymous> (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5579) at node_modules/lodash/lodash.js (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5586) at __require (node_modules_taro_tt_prebundle_react_js.js:27) at entry:lodash (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5592) at __require (node_modules_taro_tt_prebundle_react_js.js:27) at Object../node_modules/.taro/tt/prebundle/lodash.core.js (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5595) at __webpack_require__ (bootstrap:19) at Object../node_modules/.taro/tt/prebundle/lodash.js (vendors-node_modules_taro_tt_prebundle_lodash_js.js:5613) at __webpack_require__ (bootstrap:19)

环境信息

👽 Taro v3.5.7

  Taro CLI 3.5.7 environment info:
    System:
      OS: macOS 12.6
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v14.17.3/bin/yarn
      npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.7 => 3.5.7 
      @tarojs/components: 3.5.7 => 3.5.7 
      @tarojs/helper: 3.5.7 => 3.5.7 
      @tarojs/plugin-framework-react: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-alipay: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-jd: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-qq: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-swan: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-tt: 3.5.7 => 3.5.7 
      @tarojs/plugin-platform-weapp: 3.5.7 => 3.5.7 
      @tarojs/react: 3.5.7 => 3.5.7 
      @tarojs/router: 3.5.7 => 3.5.7 
      @tarojs/runtime: 3.5.7 => 3.5.7 
      @tarojs/shared: 3.5.7 => 3.5.7 
      @tarojs/taro: 3.5.7 => 3.5.7 
      @tarojs/taro-h5: 3.5.7 => 3.5.7 
      @tarojs/webpack5-runner: 3.5.7 => 3.5.7 
      babel-preset-taro: 3.5.7 => 3.5.7 
      eslint-config-taro: 3.5.7 => 3.5.7 
      react: ^18.0.0 => 18.2.0 
      taro-ui: ^3.1.0-beta.2 => 3.1.0-beta.4 

补充信息

就是通过 taro cli 中的 react 基础模版生成的全新项目,lodash也是模版自带的版本。 在编译 字节小程序时如果使用了 lodash 的 cloneDeep 方法的话会有报错。 3.3.19版本能够正常运行。

TheKonka commented 1 year ago

https://blog.xinshangshangxin.com/2016/11/30/mina-lodash/

Rlagnl commented 1 year ago

https://blog.xinshangshangxin.com/2016/11/30/mina-lodash/

遗憾的是微信小程序和h5是可以正常运行的,没有这个问题,只有字节小程序上会有。而且taro 3.3.19上也能正常运行,所以只能认为是taro 做新版本中对编译配置做了一些调整导致了这个问题的出现。

Chen-jj commented 1 year ago

关闭 prebundle 再试试

Rlagnl commented 1 year ago

prebundle

@Chen-jj 试了以下两种配置方法,均没有修复上述问题 compiler: { type: "webpack5", prebundle: false, }, compiler: { type: "webpack5", prebundle: { enable: false, }, },

BEN13459290037 commented 7 months ago

{ "message": "Cannot read properties of undefined (reading 'prototype')", "name": "TypeError", "stack": "at runInContext(pages/index.js:11809:28)\nat Object.(pages/index.js:27528:11)\nat ../../node_modules/lodash/lodash.js(pages/index.js:27547:3)\nat webpack_require(runtime.js:24:42)\nat ./src/components/FieldList/index.tsx(pages/index.js:10152:65)\nat webpack_require(runtime.js:24:42)\nat ./src/components/index.ts(pages/index.js:10311:68)\nat webpack_require__(runtime.js:24:42)\nat ../../node_modules/@tarojs/taro-loader/lib/entry-cache.js?name=pages/index!./src/pages/index.tt.tsx(pages/index.js:18:69)\nat webpack_require__(runtime.js:24:42)\n" }

mark-libn commented 2 weeks ago

参考一下这个 https://github.com/NervJS/taro/issues/13339 我也是这样搞了一下就好了