簡體   English   中英

找不到模塊“。” 或其相應的類型聲明

[英]Cannot find module '.' or its corresponding type declarations

當我在 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

這似乎是 package 本身的錯誤。 我應該如何解決這個問題? 謝謝。

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

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

將您的 cheerio 版本鎖定為 1.0.0-rc.10,它對我有用,或者,在您的 package.json 文件中將“類型”更改為“commonjs”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM