Cecilxx / echarts-taro3-react

taro3.x-react构建的微信小程序echarts组件,及使用示列
MIT License
85 stars 26 forks source link

r.addEventListener is not a function #34

Open ystyle opened 2 years ago

ystyle commented 2 years ago

VM659 WAService.js:2 TypeError: r.addEventListener is not a function
    at cr (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2
    at Array.forEach (<anonymous>)
    at z (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at hr (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at new gr (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at new br (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at wr (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at new Xc (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)
    at Object.t.init (index.js?t=wechat&s=1645691368667&v=19a5dca6bd857d1e53cc2ac053482fed:2)(env: Windows,mp,1.05.2201240; lib: 2.22.0)

这个是怎么回事呀

EOS1O commented 2 years ago

我也遇到了,请问怎么解决

ystyle commented 2 years ago

我也遇到了,请问怎么解决

https://github.com/NervJS/taro/issues/9914#issuecomment-1049706286

bingyouyujiu commented 2 years ago

找到echarts-taro3-react/lib/ec-canvas/echarts.js文件,将里面的r.addEventListener(o,a,s)改为r.addEventListener?.(o,a,s)就可以了,我也遇到了这个问题,改了之后就正常显示了

LittleTangJF commented 2 years ago

找到echarts-taro3-react/lib/ec-canvas/echarts.js文件,将里面的r.addEventListener(o,a,s)改为r.addEventListener?.(o,a,s)就可以了,我也遇到了这个问题,改了之后就正常显示了

这个bug在使用hooks写法的时候出现的,按照你说的改了就好了

jhxxs commented 2 years ago

每次用yarn安装或者移除包之后都会导致更改后的echarts.js文件被重置,可以用taro的plugin来处理:

// config/plugin/echarts.ts
import { IPluginContext } from "@tarojs/service"
import fs from "fs"
import path from "path"

export default (ctx: IPluginContext) => {
  // 接下来使用 ctx 的时候就能获得智能提示了
  ctx.onBuildStart(() => {
    const echartsJsPath = path.join(
      ctx.paths.nodeModulesPath,
      "/echarts-taro3-react/lib/ec-canvas/echarts.js"
    )

    const text = fs.readFileSync(echartsJsPath).toString()
    const str = text.replace(
      /r\??\.addEventListener\(o,a,s\)/g,
      "r.addEventListener?.(o,a,s)"
    )

    fs.writeFileSync(echartsJsPath, str)
  })
}

然后在 config/index.js里配置plugins项:

// config/index.js
plugins: [
    [path.resolve(__dirname, "./plugin/echarts.ts")]
]