Ask questionsdeno cannot import file from url without context

Description

As a test, I tried to serve a .ts file with a simple node application serving at http://localhost:8080. Then I tried to import it from an other ts file executed with deno. The result was an error hard to understand (See below)

Steps to reproduce

  • Serve a simple ts file at http://localhost:8080
  • Execute an other ts file with deno containing :
import  test from 'http://localhost:8080';

Logs

DEBUG TS - getScriptVersion() /home/chococrok/git_repos/deno/test1.ts 
DEBUG TS - getScriptKind() /home/chococrok/git_repos/deno/test1.ts
DEBUG TS - getCompilationSettings()
DEBUG TS - getDefaultLibFileName()
DEBUG TS - compiler._resolveModule { moduleSpecifier: "$asset$/lib.deno_runtime.d.ts", containingFile: "" }
DEBUG TS - compiler._resolveFileName { moduleSpecifier: "$asset$/lib.deno_runtime.d.ts", containingFile: "" }
DEBUG TS - resolveModule sourceCode length: 83663
DEBUG TS - resolveModule has media type: TypeScript
DEBUG TS - compiler._setFileName { moduleSpecifier: "$asset$/lib.deno_runtime.d.ts", containingFile: "" }
DEBUG TS - resolveModuleNames() { moduleNames: [ "http://localhost:8080", "https://deno.land/std/http/server.ts" ], containingFile: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG TS - compiler._resolveModule { moduleSpecifier: "http://localhost:8080", containingFile: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG TS - compiler._resolveFileName { moduleSpecifier: "http://localhost:8080", containingFile: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG TS - os.fetchModuleMetaData { specifier: "http://localhost:8080", referrer: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG RS - fetch_module_meta_data. specifier http://localhost:8080 referrer /home/chococrok/git_repos/deno/test1.ts
DEBUG RS - resolve_module specifier http://localhost:8080 referrer /home/chococrok/git_repos/deno/test1.ts
DEBUG RS - module_name: http://localhost:8080/, filename: /home/chococrok/.cache/deno/deps/http/localhost_PORT8080/
DEBUG RS - fetch local or reload http://localhost:8080/ is_module_remote true
DEBUG RS - msg_from_js FetchModuleMetaData sync true
DEBUG RS - op err Is a directory (os error 21)
DEBUG RS - msg_from_js WorkerPostMessage sync true
DEBUG RS - Got message from worker: {"success":false,"cmdId":1,"data":{"message":"Uncaught Other: Is a directory (os error 21)","sourceLine":"                    return new DenoError(kind, base.error());","scriptResourceName":"gen/cli/bundle/compiler.js","lineNumber":131177,"startPosition":9377027,"endPosition":9377028,"errorLevel":8,"startColumn":27,"endColumn":28,"isSharedCrossOrigin":false,"isOpaque":false,"frames":[{"line":131166,"column":21,"functionName":"DenoError","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":true,"isWasm":false},{"line":131177,"column":28,"functionName":"maybeError","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":131181,"column":29,"functionName":"maybeThrowError","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":132763,"column":21,"functionName":"sendSync","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":133466,"column":33,"functionName":"fetchModuleMetaData","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":133843,"column":56,"functionName":"_resolveModule","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":133984,"column":53,"functionName":"resolveModuleNames","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":127083,"column":150,"functionName":"compilerHost.resolveModuleNames","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":94303,"column":139,"functionName":"resolveModuleNamesWorker","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":94545,"column":36,"functionName":"resolveModuleNamesReusingOldState","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false}]}}
DEBUG TS - getMessage
DEBUG RS - Cmd id for get message handler: 1
DEBUG RS - msg_from_js WorkerGetMessage sync false
DEBUG RS - Received message from worker
DEBUG RS - compiler error exiting!
Uncaught Other: Is a directory (os error 21)
    at DenoError (js/errors.ts:22:5)
    at maybeError (js/errors.ts:33:12)
    at maybeThrowError (js/errors.ts:39:15)
    at sendSync (js/dispatch.ts:86:5)
    at fetchModuleMetaData (js/os.ts:73:19)
    at _resolveModule (js/compiler.ts:255:38)
    at resolveModuleNames (js/compiler.ts:486:35)
    at compilerHost.resolveModuleNames (third_party/node_modules/typescript/lib/typescript.js:121106:138)
    at resolveModuleNamesWorker (third_party/node_modules/typescript/lib/typescript.js:88311:127)
    at resolveModuleNamesReusingOldState (third_party/node_modules/typescript/lib/typescript.js:88553:24)
denoland/deno

Answer questions ry

Ah, yes I can imagine our code doesn't cover code at the root...

Just off the top of my head, I think a fix would involve doing a test similar to this: https://github.com/denoland/deno/blob/b413cd5afd6b74b3e50bf6dbb5972ea7df9f34fd/cli/deno_dir.rs#L1001-L1078 But do have a look around at some of the other tests in cli/deno_dir.rs, some other might be more appropriate to copy. Hope that helps - if not, let me know, I can dig in and provide more guidance.