dnt icon indicating copy to clipboard operation
dnt copied to clipboard

src/deps/deno.land/[email protected]/log/handlers.ts:182:5 - error TS2304: Cannot find name 'removeEventListener'.

Open denizdogan opened this issue 2 years ago • 2 comments

I don't know if I'm doing something completely wrong, but I can't seem to get past this issue. I am just using the regular log module from deno_std and whenever I try to use dnt, I get stuck on this particular problem.

Here is my build script:

import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";

let version = Deno.args[0];

if (version?.startsWith("v")) {
  console.warn(`stripping leading 'v' from '${version}'`);
  version = version.slice(1);
}

if (!version) {
  console.error("error: version is required");
  Deno.exit(1);
}

await emptyDir("./npm");

await build({
  entryPoints: ["./mod.ts"],
  outDir: "./npm",
  shims: {
    crypto: true,
    deno: true,
    undici: true,
  },
  package: {
    name: "[redacted]",
    version: version,
    description: "[redacted]",
    repository: {
      type: "git",
      url: "git+https://github.com/[redacted]",
    },
    license: "SEE LICENSE IN LICENSE",
    author: "Deniz Dogan <yadayadayada>",
  },
  postBuild() {
    Deno.copyFileSync("LICENSE", "npm/LICENSE");
    Deno.copyFileSync("README.md", "npm/README.md");
  },
});
❯ node --version
v20.2.0

~/code/my_project main*
❯ deno --version
deno 1.34.0 (release, aarch64-apple-darwin)
v8 11.5.150.1
typescript 5.0.4

~/code/my_project main*
❯ deno task dnt v0.0.1
Task dnt deno task clean && deno task fmt --check && deno task lint && deno task test && deno run --unstable --allow-all scripts/build_npm.ts "v0.0.1"
Task clean rm -rf npm .coverage
Task fmt deno fmt --unstable "--check"
Checked 45 files
Task lint deno lint --unstable
Checked 30 files
Task test deno test --unstable
running 1 test from ./[redacted].ts
[redacted] ... ok (26ms)
running 0 tests from ./[redacted].ts

ok | 1 passed (2 steps) | 0 failed (82ms)

stripping leading 'v' from 'v0.0.1'
[dnt] Transforming...
[dnt] Running npm install...

added 14 packages, and audited 15 packages in 6s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[dnt] Building project...
[dnt] Type checking ESM...
src/deps/deno.land/[email protected]/log/handlers.ts:153:5 - error TS2304: Cannot find name 'addEventListener'.

153     addEventListener("unload", this.#unloadCallback);
        ~~~~~~~~~~~~~~~~
src/deps/deno.land/[email protected]/log/handlers.ts:182:5 - error TS2304: Cannot find name 'removeEventListener'.

182     removeEventListener("unload", this.#unloadCallback);
        ~~~~~~~~~~~~~~~~~~~

error: Uncaught Error: Had 2 diagnostics.
          throw new Error(`Had ${diagnostics.length} diagnostics.`);
                ^
    at getProgramAndMaybeTypeCheck (https://deno.land/x/[email protected]/mod.ts:446:17)
    at build (https://deno.land/x/[email protected]/mod.ts:339:17)
    at eventLoopTick (ext:core/01_core.js:182:11)
    at async file:///Users/deniz/code/my_project/scripts/build_npm.ts:17:1

I don't think I'm using the deno_std log module in any spectacular way, nothing fancy going on, pretty much just this:

import { log as Log } from "../../deps.ts";

export const log = () => Log.getLogger("myproject.foobar");

And here is deps.ts:

// /std/
export * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";
export * as log from "https://deno.land/[email protected]/log/mod.ts";
export {
  assertEquals,
  assertInstanceOf,
  assertNotEquals,
  assertThrows,
} from "https://deno.land/[email protected]/testing/asserts.ts";
export { describe, it } from "https://deno.land/[email protected]/testing/bdd.ts";
export type {
  AssertTrue,
  Has,
} from "https://deno.land/[email protected]/testing/types.ts";

// /x/
export { z } from "https://deno.land/x/[email protected]/mod.ts";

// npm:
export { c, t } from "npm:[email protected]";
export * as xml2js from "npm:fast-xml-parser@4";

denizdogan avatar May 29 '23 21:05 denizdogan

It's erroring correctly because addEventListener and removeEventListener are not available in Node.js.

That said, the FileLogger is what uses this https://deno.land/[email protected]/log/handlers.ts?source and your code doesn't use that so you can probably just upgrade to the latest dnt and ignore these errors by using the filterDiagnostic hook (https://github.com/denoland/dnt#ignoring-specific-type-checking-errors):

await build({
  // etc...
  filterDiagnostic(diagnostic) {
    if (diagnostic.file?.fileName.endsWith("/log/handlers.ts")) {
      return false;
    }
    return true;
  }
})

dsherret avatar Jun 02 '23 14:06 dsherret

@dsherret Thanks, I'll try your suggestion. But just to verify, is there literally no Node.js equivalent of addEventListener and removeEventListener at all, or have they simply not been shimmed yet? I'd love to help out if at all possible.

denizdogan avatar Jun 03 '23 15:06 denizdogan