最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to fix eslint error 'pendo is not defined' in my react application - Stack Overflow

programmeradmin2浏览0评论

I'm trying to add pendo snippet in my react application I have included the javascript snippet and I use pendo.initialize({visitor:{id:'id'}) I validate using pendo.validateInstall(), all works fine but I've encountered a eslint error "pendo is not defined" in pendo.initialize({visitor:{id:'id'}) which is used at my promise handler.

My screenshot is here

I'm trying to add pendo snippet in my react application I have included the javascript snippet and I use pendo.initialize({visitor:{id:'id'}) I validate using pendo.validateInstall(), all works fine but I've encountered a eslint error "pendo is not defined" in pendo.initialize({visitor:{id:'id'}) which is used at my promise handler.

My screenshot is here

Share Improve this question edited Mar 27, 2019 at 12:19 Filip Cordas 2,5711 gold badge13 silver badges24 bronze badges asked Mar 27, 2019 at 11:44 Revathy ArunachalamRevathy Arunachalam 311 silver badge2 bronze badges 3
  • ESLint tells you it's not defined because it doesn't know about it. It's not in the current file and I suspect it's some sort of global but without a visibility from the current location to the declaration and a thorough map of the dataflow of the application (which is beyond the scope of ESLint), it has no way of knowing that pendo will be declared and assigned a value by the time your code reaches the line with pendo.initialize. – VLAZ Commented Mar 27, 2019 at 11:48
  • Probably don't have the import of the module on top of the file. Most likely they have a proper js module so you don't have to use global variables – Filip Cordas Commented Mar 27, 2019 at 11:53
  • stackoverflow./questions/44877904/… I resolved that ESLint error using this thank you all for responding. – Revathy Arunachalam Commented Mar 27, 2019 at 12:07
Add a ment  | 

3 Answers 3

Reset to default 3

Instead of using

pendo.initialize({visitor:{id:'id'})

use

window.pendo.initialize({visitor:{id:'id'})

You can add globals in the eslint configuration.

"globals": {
    "pendo": true
}

If you want to override the error message just in one file, you add the following on top of your javascript file.

/* global pendo */

Checkout the eslint global documentation.

You can install "@types/pendo-io-browser" package with types for pendo.io https://www.npmjs./package/@types/pendo-io-browser

And add this type to your tsconfig.json:

    "pilerOptions": {
    "types": [
      "pendo-io-browser"
    ]
  }

After this just use pendo as any const without import. Works fine for me

pendo.initialize({})
发布评论

评论列表(0)

  1. 暂无评论