Deno: Relative import uses HTTP from module loaded over HTTPS

Created on 7 Oct 2018  路  4Comments  路  Source: denoland/deno

entry.ts

import message from "./dep";
console.log(message);

dep.ts

export default "success";

Running entry.ts locally works fine:

$ deno entry
success

When attempting to run entry.ts over HTTPS, it:

  • Loads entry.ts fine.
  • Attempts to load dep.ts over HTTP rather than HTTPS.
  • Gets a redirect to HTTPS, but does not follow it (see #931).
  • Fails to find dep.ts.

$ deno -D -r --recompile https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry
DEBUG RS - starting background reactor
DEBUG RS - msg_from_js Start sync true
DEBUG JS - cwd /home/ns/dev/deno/deno-remote-import-bug
DEBUG JS - args [ "https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry" ]
DEBUG JS - compiler.run { moduleSpecifier: "https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry", containingFile: "/home/ns/dev/deno/deno-remote-import-bug/" }
DEBUG JS - compiler.resolveModule { moduleSpecifier: "https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry", containingFile: "/home/ns/dev/deno/deno-remote-import-bug/" }
DEBUG JS - compiler.resolveFileName { moduleSpecifier: "https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry", containingFile: "/home/ns/dev/deno/deno-remote-import-bug/" }
DEBUG JS - os.ts codeFetch https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry /home/ns/dev/deno/deno-remote-import-bug/
DEBUG RS - code_fetch. module_specifier https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry containing_file /home/ns/dev/deno/deno-remote-import-bug/
DEBUG RS - resolve_module module_specifier https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry containing_file /home/ns/dev/deno/deno-remote-import-bug/
DEBUG RS - module_name: https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry, filename: /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry
Downloading https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry
DEBUG RS - resolving host="cdn.rawgit.com", port=443
DEBUG RS - connecting to 151.139.237.11:443
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - flushed 76 bytes
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - read 596 bytes
DEBUG RS - parsed 14 headers
DEBUG RS - incoming body is content-length (104 bytes)
DEBUG RS - incoming body completed
DEBUG RS - pooling idle connection for ("https://cdn.rawgit.com", Http1)
DEBUG RS - dropping I/O source: 0
DEBUG RS - Trying https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts...
Downloading https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG RS - resolving host="cdn.rawgit.com", port=443
DEBUG RS - connecting to 151.139.237.11:443
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - flushed 79 bytes
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - read 535 bytes
DEBUG RS - parsed 14 headers
DEBUG RS - incoming body is chunked encoding
DEBUG RS - incoming chunked header: 0x33 (51 bytes)
DEBUG RS - incoming body completed
DEBUG RS - pooling idle connection for ("https://cdn.rawgit.com", Http1)
DEBUG RS - dropping I/O source: 0
DEBUG RS - set file perm to 438
DEBUG RS - load_cache /home/ns/.deno/gen/6cfe4395a52dff9e4cee4a9cf7b88d56d2d44c19.js
DEBUG RS - msg_from_js CodeFetch sync true
DEBUG JS - resolveModule sourceCode length: 51
DEBUG JS - resolveModule has outputCode: false
DEBUG JS - compiler.setFileName { moduleSpecifier: "https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry", containingFile: "/home/ns/dev/deno/deno-remote-import-bug/" }
DEBUG JS - compiler._resolveDependencies /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
Compiling https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG JS - getCurrentDirectory()
DEBUG JS - getScriptSnapshot() /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG JS - getScriptVersion() /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG JS - getScriptKind() /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG JS - getCompilationSettings()
DEBUG JS - getDefaultLibFileName()
DEBUG JS - compiler.resolveModule { moduleSpecifier: "globals.d.ts", containingFile: "$asset$" }
DEBUG JS - compiler.resolveFileName { moduleSpecifier: "globals.d.ts", containingFile: "$asset$" }
DEBUG JS - resolveModule sourceCode length: 134678
DEBUG JS - resolveModule has outputCode: true
DEBUG JS - compiler.setFileName { moduleSpecifier: "globals.d.ts", containingFile: "$asset$" }
DEBUG JS - resolveModuleNames() { moduleNames: [ "./dep" ], containingFile: "/home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts" }
DEBUG JS - compiler.resolveModule { moduleSpecifier: "./dep", containingFile: "/home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts" }
DEBUG JS - compiler.resolveFileName { moduleSpecifier: "./dep", containingFile: "/home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts" }
DEBUG JS - os.ts codeFetch ./dep /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG RS - code_fetch. module_specifier ./dep containing_file /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG RS - resolve_module module_specifier ./dep containing_file http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG RS - module_name: http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep, filename: /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep
Downloading http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep
DEBUG RS - resolving host="cdn.rawgit.com", port=80
DEBUG RS - connecting to 151.139.237.11:80
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - flushed 74 bytes
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - read 468 bytes
DEBUG RS - parsed 7 headers
DEBUG RS - incoming body is content-length (178 bytes)
DEBUG RS - incoming body completed
DEBUG RS - pooling idle connection for ("http://cdn.rawgit.com", Http1)
DEBUG RS - Trying http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep.ts...
Downloading http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep.ts
DEBUG RS - dropping I/O source: 0
DEBUG RS - resolving host="cdn.rawgit.com", port=80
DEBUG RS - connecting to 151.139.237.11:80
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - flushed 77 bytes
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - read 471 bytes
DEBUG RS - parsed 7 headers
DEBUG RS - incoming body is content-length (178 bytes)
DEBUG RS - incoming body completed
DEBUG RS - pooling idle connection for ("http://cdn.rawgit.com", Http1)
DEBUG RS - Trying http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep.js...
Downloading http://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep.js
DEBUG RS - dropping I/O source: 0
DEBUG RS - resolving host="cdn.rawgit.com", port=80
DEBUG RS - connecting to 151.139.237.11:80
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - flushed 77 bytes
DEBUG RS - loop process - 1 events, 0.000s
DEBUG RS - read 471 bytes
DEBUG RS - parsed 7 headers
DEBUG RS - incoming body is content-length (178 bytes)
DEBUG RS - incoming body completed
DEBUG RS - pooling idle connection for ("http://cdn.rawgit.com", Http1)
DEBUG RS - msg_from_js CodeFetch sync true
DEBUG RS - dropping I/O source: 0
DEBUG RS - op err Cannot resolve module "./dep" from "/home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts"
DEBUG JS - compiler.getGeneratedContents gen/bundle/main.js
DEBUG JS - compiler.getGeneratedContents main.js.map
NotFound: Cannot resolve module "./dep" from "/home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts"
    at maybeError (deno/js/errors.ts:25:12)
    at maybeThrowError (deno/js/errors.ts:14:15)
    at sendSync (deno/js/dispatch.ts:70:5)
    at Object.codeFetch (deno/js/os.ts:31:19)
    at DenoCompiler.resolveModule (deno/js/compiler.ts:525:38)
    at DenoCompiler._resolveModuleName (deno/js/compiler.ts:349:33)
    at moduleNames.map.name (deno/js/compiler.ts:657:33)
    at Array.map (<anonymous>)
    at DenoCompiler.resolveModuleNames (deno/js/compiler.ts:649:24)
    at Object.compilerHost.resolveModuleNames (deno/third_party/node_modules/typescript/lib/typescript.js:111684:117)

$ deno --version
deno: 0.1.7
v8: 7.0.276.15
bug

Most helpful comment

compiler.resolveModuleNames gets the deps cache path /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts as its containingFile argument rather than the URL, so resolve_module can't know the correct protocol to use.

Based on the ContainingFile docs, it looks like it should be passed the original URL to resolve it properly, not the cache path: https://github.com/denoland/deno/blob/ffb41e61f138a683aac5fd89e0dd72b720c929d6/js/compiler.ts#L29-L34

It has worked with http:// tests because src_file_to_url hardcodes a http:// prefix: https://github.com/denoland/deno/blob/ffb41e61f138a683aac5fd89e0dd72b720c929d6/src/deno_dir.rs#L234

All 4 comments

Thanks for the detailed report. Definitely buggy behavior.

compiler.resolveModuleNames gets the deps cache path /home/ns/.deno/deps/cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts as its containingFile argument rather than the URL, so resolve_module can't know the correct protocol to use.

Based on the ContainingFile docs, it looks like it should be passed the original URL to resolve it properly, not the cache path: https://github.com/denoland/deno/blob/ffb41e61f138a683aac5fd89e0dd72b720c929d6/js/compiler.ts#L29-L34

It has worked with http:// tests because src_file_to_url hardcodes a http:// prefix: https://github.com/denoland/deno/blob/ffb41e61f138a683aac5fd89e0dd72b720c929d6/src/deno_dir.rs#L234

I believe this was fixed in #934. Please open a new one if it didn't cover everything.

@ry actually not yet, the hard coded "https://" is not yet addressed and also requires changes to compiler code a bit. #934 was addressing redirect

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CruxCv picture CruxCv  路  3Comments

benjamingr picture benjamingr  路  3Comments

ry picture ry  路  3Comments

zugende picture zugende  路  3Comments

ry picture ry  路  3Comments