1

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

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

我的简单代码在这里。

部门

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

测试3.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)
4

2 回答 2

2
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'
于 2020-05-14T14:57:37.670 回答
0

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

于 2020-05-14T14:56:10.577 回答