【问题标题】:Unable to import dependency in deno dep.ts file in another class无法在另一个类的 deno dep.ts 文件中导入依赖项
【发布时间】:2020-05-14 23:23:27
【问题描述】:

我在 dep.ts 文件中提到了依赖关系,我想在另一个文件中导入引用。但我收到以下错误。请帮我解决。我正在关注下面提到的链接。

https://deno.land/manual/linking_to_external_code#it-seems-unwieldy-to-import-urls-everywhere

我的简单代码放在这里。

dep.ts

export {
    log
  } from "https://deno.land/std/log/mod.ts";

Test3.ts

import { log } from "./dep.ts";

export class Test3 {

    public show() {
        log.debug("Exploring deno ...");

    }

}

const test = new Test3();
test.show();

在执行命令 deno run Test3.ts 时,我收到以下错误。

error: Uncaught NotFound: Cannot resolve module "file:///C:/javascriptdev1/deno-test1/deps.ts" from "file:///C:/javascriptdev1/deno-test1/Test3.ts"
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
    at async processImports ($deno$/compiler.ts:736:23)
    at async processImports ($deno$/compiler.ts:753:7)
    at async compile ($deno$/compiler.ts:1316:31)
    at async tsCompilerOnMessage ($deno$/compiler.ts:1548:22)
    at async workerMessageRecvCallback ($deno$/runtime_worker.ts:74:9)

【问题讨论】:

    标签: typescript deno


    【解决方案1】:
    error: Uncaught NotFound: Cannot resolve module
    

    该错误意味着您正在导入错误的文件(不存在)。

    您正在导入 deps.ts 而不是 dep.ts


    除此之外,你想要的是:

    export * as log from "https://deno.land/std/log/mod.ts";
    
    // you can have other exports too
    export {
      assert,
      assertEquals,
      assertStrContains,
    } from "https://deno.land/std/testing/asserts.ts";
    
    

    否则你会得到:

    Module '"./deps"' has no exported member 'log'
    

    【讨论】:

    • 我的错,我更正了。顺便说一句,我有多个要导出,该怎么做,我每个都用 export 写吗?
    • 不客气 :)。添加了多个导出的示例。
    • 谢谢@Marcos。
    【解决方案2】:

    您正在从“deps.ts”导入,但文件名为“dep.ts”。确保所有内容都拼写正确。

    【讨论】:

    • 我已纠正,但我收到此错误error: TS2305 [ERROR]: Module '"https://deno.land/std/log/mod"' has no exported member 'log'.
    猜你喜欢
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多