Unable to import dependency in deno dep.ts file in another class

好久不见. 提交于 2020-05-15 19:36:25

问题


I have mentioned the dependency in dep.ts file and I want to import the reference in another file. But I am getting the following error. Please help me to resolve. I was following the link as mentioned below.

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

My simple code goes here.

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();

While executing the command deno run Test3.ts, I get the following error.

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)

回答1:


error: Uncaught NotFound: Cannot resolve module

That error means you're importing the wrong file (does not exist).

You're importing deps.ts instead of dep.ts


Aside from that, what you want is to:

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";

Otherwise you'll get:

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



回答2:


You're importing from "deps.ts" but the file name is "dep.ts". Make sure everything is spelled correctly.



来源:https://stackoverflow.com/questions/61800486/unable-to-import-dependency-in-deno-dep-ts-file-in-another-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!