denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.83k stars 5.39k forks source link

Deno vendor, cache, and remote types with X-Typescript-Types aren't working together #14575

Closed jimisaacs closed 5 months ago

jimisaacs commented 2 years ago

The following works fine:

deno cache main.ts

The following does not:

deno vendor main.ts
deno cache main.ts --import-map vendor/import_map.json
Check /deno/denodemo/main.ts
error: Uncaught AssertionError: "data" is unexpectedly null for "https://esm.sh/v78/@types/react@18.0.9/index.d.ts".
    at <anonymous> (deno:cli/tsc/99_main_compiler.js:71:13)

I get the feeling after looking through the vendor directory that some combination of deno vendor, deno cache, and remote types using the X-Typescript-Types header (i.e. https://esm.sh design), is broken.

jimisaacs commented 2 years ago

Turns out, it has something to do with having 2 deps.ts files that export the same imported react from a url (from esm.sh). I don't have a reduced case, but that's about as simple as a description as I can give right now. I deleted one of the deps.ts files, and it works without error now.

jimisaacs commented 2 years ago

Maybe related? https://github.com/denoland/deno/issues/13693

tv42 commented 2 years ago

I can reproduce this error very simply:

$ deno --version
deno 1.22.3 (release, x86_64-unknown-linux-gnu)
v8 10.3.174.6
typescript 4.6.2
$ ls
repro.ts
$ cat repro.ts
import { MeiliSearch } from "https://esm.sh/meilisearch@0.25.1";
$ deno vendor --force ./repro.ts
Vendored 172 modules into vendor/ directory.

To use vendored modules, specify the `--import-map` flag when invoking deno subcommands:
  deno run -A --import-map vendor/import_map.json ./repro.ts
$ deno bundle --import-map=vendor/import_map.json ./repro.ts
Check file:///home/tv/src/eagain.net/2022/deno-bundle-bug/repro.ts
error: Uncaught AssertionError: "data" is unexpectedly null for "https://esm.sh/v85/node.ns.d.ts".
    at <anonymous> (deno:cli/tsc/99_main_compiler.js:71:13)
$ deno run --import-map=vendor/import_map.json ./repro.ts
Check file:///home/tv/src/eagain.net/2022/deno-bundle-issue14575/repro.ts
error: Uncaught AssertionError: "data" is unexpectedly null for "https://esm.sh/v85/node.ns.d.ts".
    at <anonymous> (deno:cli/tsc/99_main_compiler.js:71:13)
CanRau commented 2 years ago

Hey just curious about the difference between cache & vendor and if the following from op would be necessary/make sense?

deno vendor main.ts
deno cache main.ts --import-map vendor/import_map.json

From the docs I understand that they're kinda doing similar things though vendor more "explicit" with the goal of not just caching but making more deterministically offline available.

nayeemrmn commented 2 years ago

@dsherret Should X-Typescript-Types be transformed to /// < reference types="..." /> in deno vendor?

dsherret commented 2 years ago

@nayeemrmn it should be handling x-typescript-types https://github.com/denoland/deno/blob/fd5a12d7e25dc53238e2bbcffe970e646c1035f3/cli/tools/vendor/build.rs#L505

@CanRau deno vendor is to vendor dependencies to a local directory and use those instead of the remote dependencies. deno cache is to cache the remote dependencies to the local deno cache in case they're not already cached.

@jimisaacs would you be able to provide a repo with a reproduction?

tv42 commented 2 years ago

@jimisaacs would you be able to provide a repo with a reproduction?

There's a 1-liner repro in my earlier comment.

dsherret commented 2 years ago

@tv42 I'm not able to reproduce with that in 1.23.1. Maybe upgrade deno and this is fixed?

tv42 commented 2 years ago

With 1.23.1, I still see the deno bundle crash, but not the deno run crash:

$ podman run -it --rm docker.io/denoland/deno:alpine-1.23.1 /bin/sh
/ # echo 'import { MeiliSearch } from "https://esm.sh/meilisearch@0.25.1";' >repro.ts
/ # deno vendor --force ./repro.ts
...
Vendored 171 modules into vendor/ directory.

To use vendored modules, specify the `--import-map vendor/import_map.json` flag when invoking Deno subcommands or add an `"importMap": "<path_to_vendored_import_map>"` entry to a deno.json file.
/ # deno bundle --import-map=vendor/import_map.json ./repro.ts
Check file:///repro.ts
error: Uncaught AssertionError: "data" is unexpectedly null for "https://esm.sh/v86/node.ns.d.ts".
    at <anonymous> (deno:cli/tsc/99_main_compiler.js:80:13)
/ # deno run --import-map=vendor/import_map.json ./repro.ts
/ #
CanRau commented 2 years ago

@dsherret yea but I though vendor is basically "caching" or is it safer to cache after vendor? 🤔

lucacasonato commented 5 months ago

deno vendor is deprecated - use vendor: true in deno.json instead.