Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative import uses HTTP from module loaded over HTTPS #930

Closed
qoh opened this issue Oct 6, 2018 · 4 comments · Fixed by #971
Closed

Relative import uses HTTP from module loaded over HTTPS #930

qoh opened this issue Oct 6, 2018 · 4 comments · Fixed by #971
Labels
bug Something isn't working correctly
Milestone

Comments

@qoh
Copy link
Contributor

qoh commented Oct 6, 2018

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:


$ 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 https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/entry.ts
DEBUG RS - module_name: https://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 https://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 ("https://cdn.rawgit.com", Http1)
DEBUG RS - Trying https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep.ts...
Downloading https://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 ("https://cdn.rawgit.com", Http1)
DEBUG RS - Trying https://cdn.rawgit.com/qoh/deno-remote-import-bug/tag/dep.js...
Downloading https://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 ("https://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
@qoh qoh changed the title Deno failing to import relative path from remote module (attempts HTTP and gets redirected) Fails to import relative path from remote module (attempts HTTP and gets redirected) Oct 6, 2018
@qoh qoh changed the title Fails to import relative path from remote module (attempts HTTP and gets redirected) Relative import from module loaded over HTTPS attempts to use HTTP Oct 6, 2018
@qoh qoh changed the title Relative import from module loaded over HTTPS attempts to use HTTP Relative import uses HTTP from module loaded over HTTPS Oct 6, 2018
@ry ry added the bug Something isn't working correctly label Oct 7, 2018
@ry ry added this to the v0.2 milestone Oct 7, 2018
@ry
Copy link
Member

ry commented Oct 7, 2018

Thanks for the detailed report. Definitely buggy behavior.

@qoh
Copy link
Contributor Author

qoh commented Oct 8, 2018

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:

deno/js/compiler.ts

Lines 29 to 34 in ffb41e6

/**
* The location that a module is being loaded from. This could be a directory,
* like `.`, or it could be a module specifier like
* `https://gist.github.com/somefile.ts`
*/
type ContainingFile = string;

It has worked with https:// tests because src_file_to_url hardcodes a https:// prefix:

"https://".to_string() + &rest

@ry
Copy link
Member

ry commented Oct 11, 2018

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

@ry ry closed this as completed Oct 11, 2018
@kevinkassimo
Copy link
Contributor

kevinkassimo commented Oct 11, 2018

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants