Skip to content

Cannot find name 'jsdom' #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xiaoyuhen opened this issue May 7, 2018 · 7 comments
Open

Cannot find name 'jsdom' #5

xiaoyuhen opened this issue May 7, 2018 · 7 comments

Comments

@xiaoyuhen
Copy link

xiaoyuhen commented May 7, 2018

hello simon

In my project jest-environment-jsdom-global can run normally,
But jslint will prompt me 'Cannot find name 'jsdom'

my tslint version is "^5.10.0",should i ignore this waring?

@simon360
Copy link
Owner

simon360 commented May 9, 2018

Hm, strange one. I've only used eslint, but actually, the behavior you're describing is what I would have expected to happen there, too.

Since I haven't used tslint before, I'm not sure what the solution is. Ignoring may be the best option.

Open to any suggestions or PRs on this, though!

@xiaoyuhen
Copy link
Author

xiaoyuhen commented May 9, 2018

Add this line will solve this problem
declare var jsdom: any

But I think this is not an elegant solution

@simon360
Copy link
Owner

Another solution is to refer to global.jsdom, rather than jsdom. Again, though, this lacks elegance.

@quantuminformation
Copy link

quantuminformation commented Sep 12, 2018

Any elegant solutions planned for TS users?
@simon360 where are you getting global.jsdom from?

@simon360
Copy link
Owner

@quantuminformation this isn’t on my radar right now, but I’d love to see a pull request!

@stephanie
Copy link

stephanie commented May 15, 2019

FYI, for others that have experienced this issue, we fixed this by referring to global.jsdom as @simon360 offered as a potential solution but we also had to declare JSDOM in our globals.d.ts file like this:

import { JSDOM } from 'jsdom';

declare global {
  namespace NodeJS {
    interface Global {
      jsdom: JSDOM;
    }
  }
}

For more information on the globals file: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-d-ts.html

@eightHundreds
Copy link

eightHundreds commented Jul 5, 2019

// global.d.ts
import { JSDOM } from 'jsdom';

declare global {
  namespace globalThis {
    const jsdom: JSDOM;
  }
}

easier

// global.d.ts
import { JSDOM } from 'jsdom';

declare global {
    const jsdom: JSDOM;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants