echarts-taro3-react icon indicating copy to clipboard operation
echarts-taro3-react copied to clipboard

r.addEventListener is not a function

Open ystyle opened this issue 2 years ago • 5 comments


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)

这个是怎么回事呀

ystyle avatar Feb 24 '22 09:02 ystyle

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

EOS1O avatar Mar 03 '22 12:03 EOS1O

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

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

ystyle avatar Mar 03 '22 12:03 ystyle

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

bingyouyujiu avatar Mar 12 '22 02:03 bingyouyujiu

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

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

LittleTangJF avatar Mar 31 '22 07:03 LittleTangJF

每次用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")]
]

jhxxs avatar Jun 01 '22 03:06 jhxxs