deno: Compile error when code contains export declaration-like string
- v0.20.0
- Parser doesn’t find declarations correctly?
[EDITED]
Previous example has unrelated mistake but I don’ know which code can reproduce error I met.
I met this error when I ran -> https://raw.githubusercontent.com/keroxp/dink/v0.5.1/main.ts That can be compiled with deno@v0.19.0. But got error below with v0.20.0:
error: Uncaught ImportPrefixMissing: relative import path "${resp.url}" not prefixed with / or ./ or ../
► $deno$/dispatch_json.ts:40:11
at DenoError ($deno$/errors.ts:20:5)
at unwrapResponse ($deno$/dispatch_json.ts:40:11)
at sendAsync ($deno$/dispatch_json.ts:85:10)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 26 (23 by maintainers)
Hmm, there doesn’t seem to be a problem?
${deno}in a template literal gets substituted with the value assigned to variabledeno, which you haven’t declared.Yeah, it is a TypeScript issue with
preProcessFile. Funnily, it was already open and tagged as a bug, but the reverse. It seems string literals with a variable interpolation in them cause the parser to flip modes, not detecting import/export statements outside of string literals, and detecting them within string literals. I can’t see any easy way to fix it right now. The workaround might be the best thing until the bug is fixed.Refs: microsoft/TypeScript#30878
Interesting bug @keroxp!
I looks like output from
ts.preProcessFile()incli/js/compiler.tsreturn this template string as an actual import.Calling @kitsonk for help
EDIT: IMHO this is a TypeScript bug - it shouldn’t treat imports inside template string as an actual import in the file.
@keroxp a quick workaround for now would be to replace template strings and just add strings old-school (
str1 + str2).@keroxp I can take a look later, can you provide repro commands?
EDIT: Nvm, running
deno https://raw.githubusercontent.com/keroxp/dink/v0.5.1/main.tsgives this error. I’ll investigate it 😃