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

Try to get oak running under dnt #14

Closed
piscisaureus opened this issue Nov 9, 2021 · 14 comments
Closed

Try to get oak running under dnt #14

piscisaureus opened this issue Nov 9, 2021 · 14 comments
Assignees

Comments

@piscisaureus
Copy link
Member

No description provided.

@kitsonk
Copy link

kitsonk commented Nov 16, 2021

@dsherret I took the first stab at this on https://github.com/oakserver/oak/tree/node

I added _build_node.ts and the script runs... but I get a big ole set of tsc diagnostics and then it just terminates and I don't get any transpiled files.

@dsherret
Copy link
Member

Current diagnostics in latest main (sorry, I meant to do a release yesterday that would have fixed a ton of the diagnostics):

npm/src/deploy_test.ts:8:59 - error TS2339: Property 'emit' does not exist on type 'typeof Deno'.

8   return !(Deno && "emit" in Deno && typeof denoShim.Deno.emit === "function");
                                                            ~~~~
npm/src/deps/deno_land/std_0.114.0/async/pool.ts:67:10 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<R>'.
  Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<R>'.

67   return res.readable[Symbol.asyncIterator]();
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno_land/std_0.114.0/crypto/mod.ts:195:42 - error TS2339: Property 'DigestContext' does not exist on type 'typeof import("V:/oak/npm/src/deps/deno_land/std_0.114.0/_wasm_crypto/crypto")'.        

195           const context = new wasmCrypto.DigestContext(name);
                                             ~~~~~~~~~~~~~
npm/src/deps/deno_land/std_0.114.0/crypto/mod.ts:236:27 - error TS2339: Property 'digest' does not exist on type 'typeof import("V:/oak/npm/src/deps/deno_land/std_0.114.0/_wasm_crypto/crypto")'.

236         return wasmCrypto.digest(algorithm.name, bytes, algorithm.length)
                              ~~~~~~
npm/src/deps/deno_land/std_0.114.0/crypto/mod.ts:239:40 - error TS2339: Property 'DigestContext' does not exist on type 'typeof import("V:/oak/npm/src/deps/deno_land/std_0.114.0/_wasm_crypto/crypto")'.        

239         const context = new wasmCrypto.DigestContext(algorithm.name);
                                           ~~~~~~~~~~~~~
npm/src/deps/deno_land/std_0.114.0/http/server.ts:456:34 - error TS2339: Property 'serveHttp' does not exist on type 'typeof Deno'.

456         httpConn = denoShim.Deno.serveHttp(conn);
                                     ~~~~~~~~~
npm/src/deps/deno_land/std_0.114.0/http/server_legacy.ts:99:35 - error TS2345: Argument of type 'Response' is not assignable to parameter of type 'import("V:/oak/npm/src/deps/deno_land/std_0.114.0/http/server_legacy").Response'.
  Types of property 'body' are incompatible.
    Type 'ReadableStream<Uint8Array> | null' is not assignable to type 'string | Uint8Array | Reader | undefined'.
      Type 'null' is not assignable to type 'string | Uint8Array | Reader | undefined'.

99       await writeResponse(this.w, r);
                                     ~
npm/src/deps/deno_land/std_0.114.0/io/buffer.ts:433:13 - error TS2339: Property 'cause' does not exist on type 'PartialReadError'.

433           e.cause = err.cause;
                ~~~~~
npm/src/deps/deno_land/std_0.114.0/io/buffer.ts:433:25 - error TS2339: Property 'cause' does not exist on type 'Error'.

433           e.cause = err.cause;
                            ~~~~~
npm/src/deps/deno_land/std_0.114.0/io/buffer.ts:619:13 - error TS2339: Property 'cause' does not exist on type 'PartialReadError'.

619           e.cause = err.cause;
                ~~~~~
npm/src/deps/deno_land/std_0.114.0/io/buffer.ts:619:25 - error TS2339: Property 'cause' does not exist on type 'Error'.

619           e.cause = err.cause;
                            ~~~~~
npm/src/deps/deno_land/std_0.114.0/io/buffer.ts:664:13 - error TS2339: Property 'cause' does not exist on type 'PartialReadError'.

664           e.cause = err.cause;
                ~~~~~
npm/src/deps/deno_land/std_0.114.0/io/buffer.ts:664:25 - error TS2339: Property 'cause' does not exist on type 'Error'.

664           e.cause = err.cause;
                            ~~~~~
npm/src/deps/deno_land/std_0.114.0/ws/mod.ts:14:9 - error TS2339: Property 'hasOwn' does not exist on type 'ObjectConstructor'.

14 const { hasOwn } = Object;
           ~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:461:58 - error TS2339: Property 'emit' does not exist on type 'typeof Deno'.

461       const { diagnostics, files } = await denoShim.Deno.emit(this.#specifier, {
                                                             ~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:559:7 - error TS2345: Argument of type '{ name: string; type: "module"; deno: { permissions: { net: boolean; read: string | boolean; }; }; }' is not 
assignable to parameter of type 'WorkerOptions'.
  Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.

559       deno: { permissions: { net: true, read: isLocal ? true : "inherit" } },
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:611:60 - error TS2694: Namespace '"V:/oak/npm/node_modules/deno.ns/lib/deno.ns.lib".Deno' has no exported member 'Diagnostic'.

611   check(options: CheckOptions = {}): Promise<denoShim.Deno.Diagnostic[]> {
                                                               ~~~~~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:781:38 - error TS2339: Property 'serveHttp' does not exist on type 'typeof Deno'.

781       const httpConn = denoShim.Deno.serveHttp(conn);
                                         ~~~~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:918:26 - error TS2694: Namespace '"V:/oak/npm/node_modules/deno.ns/lib/deno.ns.lib".Deno' has no exported member 'Diagnostic'.

918 ): Promise<denoShim.Deno.Diagnostic[]> {
                             ~~~~~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:958:47 - error TS2339: Property 'emit' does not exist on type 'typeof Deno'.

958   const { diagnostics } = await denoShim.Deno.emit(specifier, {
                                                  ~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:969:32 - error TS7006: Parameter 'diagnostic' implicitly has an 'any' type.

969     return diagnostics.filter((diagnostic) => {
                                   ~~~~~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:974:48 - error TS7006: Parameter 'ri' implicitly has an 'any' type.

974           diagnostic.relatedInformation?.some((ri) =>
                                                   ~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/testing.ts:8:63 - error TS2694: Namespace '"V:/oak/npm/node_modules/deno.ns/lib/deno.ns.lib".Deno' has no exported member 'Diagnostic'.

8 export function assertDiagnostics(diagnostics?: denoShim.Deno.Diagnostic[]): void {
                                                                ~~~~~~~~~~
npm/src/deps/deno_land/x/dectyl_0.10.7/lib/testing.ts:10:31 - error TS2339: Property 'formatDiagnostics' does not exist on type 'typeof Deno'.

10     console.log(denoShim.Deno.formatDiagnostics(diagnostics));
                                 ~~~~~~~~~~~~~~~~~
npm/src/etag.ts:49:52 - error TS2339: Property 'subtle' does not exist on type 'typeof webcrypto'.

49   const hash = base64.encode(await denoShim.crypto.subtle.digest("SHA-1", entity))
                                                      ~~~~~~
npm/src/http_server_native.ts:282:12 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<NativeRequest>'.
  Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<NativeRequest>'.

282     return stream[Symbol.asyncIterator]();
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/structured_clone.ts:149:29 - error TS2339: Property 'core' does not exist on type 'typeof Deno'.

149 const core = denoShim.Deno?.core;
                                ~~~~
npm/src/util.ts:58:40 - error TS2339: Property 'subtle' does not exist on type 'typeof webcrypto'.

58   const buffer = await denoShim.crypto.subtle.digest(
                                          ~~~~~~
npm/src/util.ts:60:21 - error TS2339: Property 'getRandomValues' does not exist on type 'typeof webcrypto'.

60     denoShim.crypto.getRandomValues(new Uint8Array(256)),
                       ~~~~~~~~~~~~~~~
npm/src/util.ts:66:40 - error TS2339: Property 'subtle' does not exist on type 'typeof webcrypto'.

66   const buffer = await denoShim.crypto.subtle.digest(
                                          ~~~~~~
npm/src/util.ts:68:21 - error TS2339: Property 'getRandomValues' does not exist on type 'typeof webcrypto'.

68     denoShim.crypto.getRandomValues(new Uint8Array(256)),
                       ~~~~~~~~~~~~~~~
npm/src/util.ts:461:26 - error TS2339: Property 'subtle' does not exist on type 'typeof webcrypto'.

461   return denoShim.crypto.subtle.sign("HMAC", key, data);
                             ~~~~~~

@dsherret
Copy link
Member

dsherret commented Nov 16, 2021

Opened deno.ns issues:

Opened dnt issues:

Not sure how to solve and I'll need to look into it more later (kind of lazy at the moment):

npm/src/deps/deno_land/std_0.114.0/async/pool.ts:67:10 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<R>'.
  Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<R>'.

67   return res.readable[Symbol.asyncIterator]();
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

npm/src/deps/deno_land/x/dectyl_0.10.7/lib/deploy_worker.ts:559:7 - error TS2345: Argument of type '{ name: string; type: "module"; deno: { permissions: { net: boolean; read: string | boolean; }; }; }' is not 
assignable to parameter of type 'WorkerOptions'.
  Object literal may only specify known properties, and 'deno' does not exist in type 'WorkerOptions'.

559       deno: { permissions: { net: true, read: isLocal ? true : "inherit" } },
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

npm/src/http_server_native.ts:282:12 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<NativeRequest>'.
  Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<NativeRequest>'.

282     return stream[Symbol.asyncIterator]();
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Looks like a bug in std. I don't see these exports (edit: maybe I didn't look hard enough... I see them know):

npm/src/deps/deno_land/std_0.114.0/crypto/mod.ts:195:42 - error TS2339: Property 'DigestContext' does not exist on type 'typeof import("V:/oak/npm/src/deps/deno_land/std_0.114.0/_wasm_crypto/crypto")'.        

195           const context = new wasmCrypto.DigestContext(name);
                                             ~~~~~~~~~~~~~
npm/src/deps/deno_land/std_0.114.0/crypto/mod.ts:236:27 - error TS2339: Property 'digest' does not exist on type 'typeof import("V:/oak/npm/src/deps/deno_land/std_0.114.0/_wasm_crypto/crypto")'.

236         return wasmCrypto.digest(algorithm.name, bytes, algorithm.length)
                              ~~~~~~

@dsherret
Copy link
Member

dsherret commented Jan 5, 2022

Current diagnostics:

npm/src/deps/deno_land/std_0.118.0/io/buffer.ts:726:3 - error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.

726   constructor(writer: Writer, size: number = DEFAULT_BUF_SIZE) {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727     if (size <= 0) {
    ~~~~~~~~~~~~~~~~~~~~
...
732     this.#writer = writer;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
733   }
    ~~~
npm/src/deps/deno_land/std_0.118.0/io/buffer.ts:827:3 - error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.

827   constructor(writer: WriterSync, size: number = DEFAULT_BUF_SIZE) {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
828     if (size <= 0) {
    ~~~~~~~~~~~~~~~~~~~~
...
833     this.#writer = writer;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
834   }
    ~~~
npm/src/http_server_native.ts:167:38 - error TS2694: Namespace '"V:/oak/npm/node_modules/@deno/shim-deno/lib/shim-deno.lib".Deno' has no exported member 'HttpConn'.

167   #httpConnections: Set<dntShim.Deno.HttpConn> = new Set();
                                         ~~~~~~~~
npm/src/http_server_native.ts:218:47 - error TS2694: Namespace '"V:/oak/npm/node_modules/@deno/shim-deno/lib/shim-deno.lib".Deno' has no exported member 'HttpConn'.

218   #trackHttpConnection(httpConn: dntShim.Deno.HttpConn): void {
                                                  ~~~~~~~~
npm/src/http_server_native.ts:222:49 - error TS2694: Namespace '"V:/oak/npm/node_modules/@deno/shim-deno/lib/shim-deno.lib".Deno' has no exported member 'HttpConn'.

222   #untrackHttpConnection(httpConn: dntShim.Deno.HttpConn): void {
                                                    ~~~~~~~~
npm/src/http_server_native.ts:282:12 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<NativeRequest>'.
  Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<NativeRequest>'.

282     return stream[Symbol.asyncIterator]();
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/middleware/proxy_test.ts:16:29 - error TS2504: Type 'ReadableStream<Uint8Array>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

16   for await (const chunk of stream) {
                               ~~~~~~
npm/src/range_test.ts:159:30 - error TS2504: Type 'MultiPartStream' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

159     for await (const part of stream) {
                                 ~~~~~~
npm/src/range_test.ts:186:30 - error TS2504: Type 'MultiPartStream' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

186     for await (const part of stream) {
                                 ~~~~~~
npm/src/structured_clone.ts:149:28 - error TS2339: Property 'core' does not exist on type 'typeof Deno'.

149 const core = dntShim.Deno?.core;
                               ~~~~

error: Uncaught (in promise) Error: Had 10 diagnostics.
      throw new Error(`Had ${diagnostics.length} diagnostics.`);
            ^
    at build (file:///V:/dnt/mod.ts:262:13)
    at async file:///V:/oak/scripts/build_npm.ts:3:1

Using my local dnt right now as it has the crypto fixes:

import { build } from "../../dnt/mod.ts";

await build({
  entryPoints: ["./mod.ts"],
  outDir: "./npm",
  shims: {
    deno: true,
    timers: true,
  },
  package: {
    // package.json properties
    name: "oak",
    version: Deno.args[0],
    description: "Your package.",
    license: "MIT",
    repository: {
      type: "git",
      url: "git+https://github.com/username/package.git",
    },
    bugs: {
      url: "https://github.com/username/package/issues",
    },
  },
});

// post build steps
Deno.copyFileSync("LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");

Issues:

@bartlomieju
Copy link
Member

The first two diagnostics, are strange to say at least. I wonder why we don't these problems in deno_std's CI?

@dsherret
Copy link
Member

@bartlomieju it is what happens when not targeting ESNext ☹. I may write a transform to handle it, but I'm not sure.

Current diagnostics (using node-fetch and I have some upcoming fixes for dnt):

npm/src/body.ts:189:53 - error TS2339: Property 'getReader' does not exist on type 'ReadableStream<any> | NodeJS.ReadableStream'.
  Property 'getReader' does not exist on type 'ReadableStream'.

189               readerFromStreamReader(readableStream.getReader()),
                                                        ~~~~~~~~~
npm/src/body.ts:285:58 - error TS2339: Property 'getReader' does not exist on type 'ReadableStream'.

285         value: readerFromStreamReader(this.#request.body.getReader()),
                                                             ~~~~~~~~~
npm/src/body.ts:296:60 - error TS2339: Property 'tee' does not exist on type 'ReadableStream<Uint8Array> | NodeJS.ReadableStream'.
  Property 'tee' does not exist on type 'ReadableStream'.

296       const streams = (this.#stream ?? this.#request.body).tee();
                                                               ~~~
npm/src/body_test.ts:196:47 - error TS2345: Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'BodyInit | null | undefined'.
  Type 'ReadableStream<Uint8Array>' is not assignable to type 'Buffer'.

196     const actual = await new dntShim.Response(body.value).text();
                                                  ~~~~~~~~~~
npm/src/body_test.ts:493:46 - error TS2345: Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'BodyInit | null | undefined'.

493     const textA = await new dntShim.Response(a.value).text();
                                                 ~~~~~~~
npm/src/body_test.ts:494:46 - error TS2345: Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'BodyInit | null | undefined'.

494     const textB = await new dntShim.Response(b.value).text();
                                                 ~~~~~~~
npm/src/deps/deno_land/std_0.118.0/io/buffer.ts:726:3 - error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.

726   constructor(writer: Writer, size: number = DEFAULT_BUF_SIZE) {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727     if (size <= 0) {
    ~~~~~~~~~~~~~~~~~~~~
...
732     this.#writer = writer;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
733   }
    ~~~
npm/src/deps/deno_land/std_0.118.0/io/buffer.ts:827:3 - error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.

827   constructor(writer: WriterSync, size: number = DEFAULT_BUF_SIZE) {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
828     if (size <= 0) {
    ~~~~~~~~~~~~~~~~~~~~
...
833     this.#writer = writer;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
834   }
    ~~~
npm/src/http_server_native.ts:89:5 - error TS2322: Type 'ReadableStream | null' is not assignable to type 'ReadableStream<Uint8Array> | null'.
  Type 'ReadableStream' is missing the following properties from type 'ReadableStream<Uint8Array>': locked, cancel, getReader, pipeThrough, and 2 more.

89     return this.#request.body;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/http_server_native.ts:167:38 - error TS2694: Namespace '"V:/oak/npm/node_modules/@deno/shim-deno/lib/shim-deno.lib".Deno' has no exported member 'HttpConn'.

167   #httpConnections: Set<dntShim.Deno.HttpConn> = new Set();
                                         ~~~~~~~~
npm/src/http_server_native.ts:218:47 - error TS2694: Namespace '"V:/oak/npm/node_modules/@deno/shim-deno/lib/shim-deno.lib".Deno' has no exported member 'HttpConn'.

218   #trackHttpConnection(httpConn: dntShim.Deno.HttpConn): void {
                                                  ~~~~~~~~
npm/src/http_server_native.ts:222:49 - error TS2694: Namespace '"V:/oak/npm/node_modules/@deno/shim-deno/lib/shim-deno.lib".Deno' has no exported member 'HttpConn'.

222   #untrackHttpConnection(httpConn: dntShim.Deno.HttpConn): void {
                                                    ~~~~~~~~
npm/src/http_server_native.ts:282:12 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<NativeRequest>'.
  Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<NativeRequest>'.

282     return stream[Symbol.asyncIterator]();
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/middleware/proxy.ts:196:3 - error TS2322: Type 'ReadableStream<Uint8Array>' is not assignable to type 'BodyInit | null'.
  Type 'ReadableStream<Uint8Array>' is not assignable to type 'Buffer'.

196   return ctx.request.body({ type: "stream" }).value;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/middleware/proxy_test.ts:16:29 - error TS2504: Type 'ReadableStream<Uint8Array>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

16   for await (const chunk of stream) {
                               ~~~~~~
npm/src/range_test.ts:159:30 - error TS2504: Type 'MultiPartStream' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

159     for await (const part of stream) {
                                 ~~~~~~
npm/src/range_test.ts:186:30 - error TS2504: Type 'MultiPartStream' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

186     for await (const part of stream) {
                                 ~~~~~~
npm/src/response.ts:59:5 - error TS2322: Type 'ReadableStream<Uint8Array>' is not assignable to type 'BodyInit | undefined'.
  Type 'ReadableStream<Uint8Array>' is missing the following properties from type 'Buffer': write, toJSON, equals, compare, and 79 more.

59     result = readableStreamFromReader(body);
       ~~~~~~
npm/src/response.ts:64:5 - error TS2322: Type 'ArrayBuffer | ArrayBufferView | Blob | URLSearchParams' is not assignable to type 'BodyInit | undefined'.
  Type 'ArrayBuffer' is not assignable to type 'BodyInit | undefined'.
    Type 'ArrayBuffer' is missing the following properties from type 'Buffer': write, toJSON, equals, compare, and 76 more.

64     result = body;
       ~~~~~~
npm/src/response.ts:66:5 - error TS2322: Type 'ReadableStream<Uint8Array>' is not assignable to type 'BodyInit | undefined'.

66     result = body.pipeThrough(new Uint8ArrayTransformStream());
       ~~~~~~
npm/src/response.ts:71:5 - error TS2322: Type 'ReadableStream<Uint8Array>' is not assignable to type 'BodyInit | undefined'.

71     result = readableStreamFromAsyncIterable(body);
       ~~~~~~
npm/src/server_sent_event_test.ts:124:38 - error TS2339: Property 'getReader' does not exist on type 'ReadableStream'.

124     const reader = env.response.body.getReader();
                                         ~~~~~~~~~

error: Uncaught (in promise) Error: Had 22 diagnostics.
      throw new Error(`Had ${diagnostics.length} diagnostics.`);
            ^
    at build (file:///V:/dnt/mod.ts:271:13)
    at async file:///V:/oak/scripts/build_npm.ts:3:1

@kitsonk
Copy link

kitsonk commented Jan 11, 2022

You can target non-ESNext but use the esnext lib?

@kitsonk
Copy link

kitsonk commented Feb 14, 2022

I opened denoland/std#1917 to work around the limitation of the super() and initialised properties.

I've worked around the other type issues in oak itself, so it is almost passing type checking, I am starting getting the Node.js abstraction in for handling requests.

@kitsonk
Copy link

kitsonk commented Feb 14, 2022

Ok, with denoland/std#1917 merged my branch now builds, but fails on the tests...

Now I've run into a more fundamental issue @dsherret. Is there any way to get dnt to emit ESM modules instead of CommonJS? The problem is that you can only use TLA in ESM modules and in order to make it work, I need to optionally import some stuff using dynamic import at the top level.

For example, I have a utility class of Uint8ArrayTransformStream which transforms anything into a byte array, used for encoding the boding. It extends TransformStream, which I can use in Node.js 16.5.0 and later, which I am find limiting oak to that, but I then need to do something like this:

const TransformStream = globalThis.TransformStream ?? (await import("stream/web")).TransformStream;

But that requires TLA... I suspect there will be a lot of other minor problems as well, it seems like the default target for dnt for Deno code should really be ESM and make the package an ESM package, but have an escape hatch to convert it to CommonJS, but most Deno code should work better under emitted as ESM and already has dependencies that are ESM only.

@kitsonk
Copy link

kitsonk commented Feb 14, 2022

Ok, looks like I can skip CommonJS and UMD output, so I think I might be ok, just more configuring on the build script.

@kitsonk
Copy link

kitsonk commented Feb 21, 2022

Closed by oakserver/oak#479

@kitsonk kitsonk closed this as completed Feb 21, 2022
@riderx
Copy link

riderx commented Feb 18, 2024

@kitsonk thank you so much for the hours of research you put on this!
I had a similar issue to port https://github.com/bradenmacdonald/deno-s3-lite-client For Node.js and Cloudflare worker.
Custom was working well but failing in Cloudflare worker because it's already implemented.
So your optional solution defined here:
https://github.com/oakserver/oak/blob/main/node_shims.ts
Fixed all problems better than dnt, your solution should be integrated in the shim system!
Now I just wait for this to be merged, and I will be able to use the same package for s3 in my 3 envs!
bradenmacdonald/s3-lite-client#30

@kitsonk
Copy link

kitsonk commented Feb 19, 2024

The only thing that is valid for dnt from the approach to oak is the shimming of ErrorEvent for which I opened #375. The rest of the approach used (shimming the streams globally) can already be accomplished via dnt, but I don't use that approach as I need the code to work both with dnt and under jsr.io.

@riderx
Copy link

riderx commented Feb 24, 2024

@kitsonk I do the same path as you with shimming the streams globally to make it work on Cloudflare workers, dnt doesn't work for that case.
Maybe I was doing something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants