【问题标题】:Cannot find module '.' or its corresponding type declarationsCannot find module \'.\' or its corresponding type declarations
【发布时间】:2022-12-02 05:06:59
【问题描述】:

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

【问题讨论】:

标签: node.js typescript npm es6-modules cheerio


【解决方案1】:

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".

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 2022-12-26
    • 2022-12-28
    • 2022-12-26
    • 2022-12-27
    • 2023-01-05
    • 2022-12-02
    • 2018-12-02
    • 2023-01-12
    相关资源
    最近更新 更多