找不到模块“。” 或其相应的类型声明

Poi*_*son 5 node.js npm typescript cheerio es6-modules

当我在我的项目中使用 typescript 使用 Cheerio 时,并尝试通过 tsc 编译它。编译器抛出如下异常:

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
Run Code Online (Sandbox Code Playgroud)

这似乎是包本身的错误。我应该如何解决这个问题?谢谢。

我只在我的项目中使用cheerio,如下所示:

import * as cheerio from "cheerio";
cheerio.load(content) // The type of content is string.
Run Code Online (Sandbox Code Playgroud)

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

小智 0

将您的cheerio 版本锁定为1.0.0-rc.10,它对我有用,或者在您的package.json 文件中将“type”更改为“commonjs”。