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

triple slash references don't work in js files sometimes #22320

Open
phaux opened this issue Feb 7, 2024 · 5 comments
Open

triple slash references don't work in js files sometimes #22320

phaux opened this issue Feb 7, 2024 · 5 comments
Labels
feat new feature (which has been agreed to/accepted)

Comments

@phaux
Copy link

phaux commented Feb 7, 2024

Looks like triple slash references to remote modules don't work when there's at least 2 of them in a project:

// @ts-check
/// <reference types="npm:@types/[email protected]" />
/// <reference types="npm:[email protected]" />

VSCode says:

File 'internal:///missing_dependency.d.ts' not found. deno-ts(6053)

deno check crashes:

error: Uncaught Error: Could not find constraint '@types/[email protected]' in the list of packages.
    at ext:deno_tsc/99_main_compiler.js:654:32
    at Array.map (<anonymous>)
    at Object.resolveTypeReferenceDirectives (ext:deno_tsc/99_main_compiler.js:643:33)
    at actualResolveTypeReferenceDirectiveNamesWorker (ext:deno_tsc/00_typescript.js:119495:154)
    at resolveTypeReferenceDirectiveNamesWorker (ext:deno_tsc/00_typescript.js:119871:22)
    at resolveTypeReferenceDirectiveNamesReusingOldState (ext:deno_tsc/00_typescript.js:120033:16)
    at processTypeReferenceDirectives (ext:deno_tsc/00_typescript.js:121349:158)
    at findSourceFileWorker (ext:deno_tsc/00_typescript.js:121245:11)
    at findSourceFile (ext:deno_tsc/00_typescript.js:121115:22)
    at ext:deno_tsc/00_typescript.js:121064:24

Importing from esm.sh also doesn't work:

// @ts-check
/// <reference types="https://esm.sh/@types/[email protected]" />
/// <reference types="https://esm.sh/[email protected]" />

GM.xmlHttpRequest({ url: "/", method: "GET" });
globalThis.preact.h("div", {});

Now the last one only gets types and the rest are ignored:

Check file:///home/lis/Dropbox/userscripts/test.js
error: TS2304 [ERROR]: Cannot find name 'GM'.
GM.xmlHttpRequest({ url: "/", method: "GET" });
~~
    at file:///home/lis/Dropbox/userscripts/test.js:5:1

This only happens in js files. ts works fine.

Version: Deno 1.40.3

@dsherret dsherret added the bug Something isn't working correctly label Jun 4, 2024
@dsherret
Copy link
Member

dsherret commented Jun 4, 2024

Do you have a lockfile? I think it's corrupt. Maybe try deleting it.

Sorry, the error message is not very good here (I ran into it while debugging some stuff just now and searched the issue tracker)

@phaux
Copy link
Author

phaux commented Jun 4, 2024

It happens regardless if there's a lock file.

I found a workaround:

if (false) {
  import("npm:@types/[email protected]");
  import("npm:[email protected]");
}

@lucacasonato
Copy link
Member

You can not have more than one triple slash reference comment in a JS file. Only one is supported, and it's types will be used as the types of the JS file.

@lucacasonato lucacasonato added the working as designed this is working as intended label Jun 17, 2024
@lucacasonato
Copy link
Member

Ref denoland/docs#502

@phaux
Copy link
Author

phaux commented Jun 17, 2024

That's not just a docs issue. The error message could be better and it shouldn't crash Deno.

@lucacasonato lucacasonato reopened this Jun 17, 2024
@lucacasonato lucacasonato added feat new feature (which has been agreed to/accepted) and removed bug Something isn't working correctly working as designed this is working as intended labels Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted)
Projects
None yet
Development

No branches or pull requests

3 participants