question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module '.' or its corresponding type declarations

See original GitHub issue

when I use cheerio in my project with typescript, and try to compile it by tsc. The compiler throws an exception described below:

error TS2307: Cannot find module '.' or its corresponding type declarations.

2 import type { CheerioAPI, Cheerio } from '.'; 

Found 1 error in node_modules/cheerio/lib/esm/static.d.ts:2

This seems to be a bug in the package itself. How should I solve this problem? Thanks.

And I only use cheerio in my project like this:

import * as cheerio from "cheerio";
cheerio.load(content) // The type of content is string.

“cheerio”: “^1.0.0-rc.12” “@types/cheerio”: “^0.22.31” node v16.16.0 npm v8.16.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
manuthcommented, Sep 10, 2022

As a workaround, I recommend you to add the following to your tsconfig.jsons compilerOptions:

{
    "compilerOptions": {
        "paths": {
            "cheerio": [
                "./node_modules/cheerio/lib/index.d.ts"
            ]
        }
    }
}

This will use cheerios cjs types instead of the esm types. The type declarations look exactly the same so it fits as a workaround replacement perfectly well.

1reaction
fb55commented, Aug 22, 2022

Thanks for sending this by — the import should be updated to conform with ESM. I will make sure this is covered in the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'react' or its corresponding type ...
The editor throws errors while importing every installed library like this: Cannot find module 'react' or its corresponding type declarations.
Read more >
How to Solve cannot find module and its corresponding type ...
To solve cannot find module and its corresponding type declarations error in JavaScript, install that module and import the library in your ...
Read more >
Error "Cannot find module 'react' or its corresponding type ...
Hi @johnjohn-0472,. According to my research and testing, please try to set moduleResolution to node in your tsconfig.json file. ... If the error ......
Read more >
Cannot find module '...' or its corresponding type declarations.
/JwksManager.spec.ts:3:31 - error TS2307: Cannot find module 'jose' or its corresponding type declarations. 3 import { JWK as JWKLib } from ...
Read more >
cannot find module 'vite' or its corresponding type declarations
To solve the "Cannot find module `path` or its corresponding type declarations" error, install the types for node by running the command `npm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found