简体   繁体   中英

Cannot find module '.' or its corresponding type declarations

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

Lock your cheerio version to 1.0.0-rc.10, it worked for me, or, in your package.json file change the "type" to "commonjs".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM