在使用Deno的TypeScript项目中使用URL导入时,出现“Cannot find module ts(2307)”IDE警告

3

我刚开始使用TypeScript和Deno。我以前从未进行过任何前端开发工作。

由于我正在使用Deno,因此需要从CDN导入所有内容作为URL导入。在我的TS文件中,我有:

import { LitElement, customElement, html } from 'https://cdn.pika.dev/lit-element';

我的IDE提示我无法找到模块:

Cannot find module 'https://cdn.pika.dev/lit-element' or its corresponding type declarations.ts(2307)

Could not find module "https://cdn.pika.dev/lit-element" locally.Deno Language Server(1005)

这是我的tsconfig.json文件:

{
    "compilerOptions": {
      "experimentalDecorators": true
    }
}

程序运行良好,但IDE错误实在令人烦恼,我希望解决它。作为一个新开发者,这些警告对于弄清楚事情很重要,所以假阳性非常让人沮丧 :/


1
这个回答解决了你的问题吗?从Uri导入TypeScript模块 - Eldar
1
deno中,你需要在导入的URL末尾添加.ts - MohamadrezaRahimianGolkhandani
我将https://cdn.skypack.dev/pin/lit-element@v2.4.0-1XOpe9DTEoAR5DmPqDi1/min/lit-element.js替换了,但仍然出现Cannot find module 'https://cdn.pika.dev/lit-element' or its corresponding type declarations.ts(2307)错误。 - Nimrod Sadeh
1个回答

2

这是因为这些包没有在本地缓存。我也遇到了同样的问题,只需要执行一次命令即可解决。

deno run my-file.ts

在这之后,Deno会下载那些包并将它们缓存起来。错误应该就会消失了。

4
我遇到了同样的问题,这并没有解决它。 - toastyghost

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接