Skip to content

Error: Cannot import type declaration files. Consider importing '***' instead of '@types/***'. #457

@quadratz

Description

@quadratz

Steps to reproduce

Directory structure

.
├── deno.json
├── dnt.ts
└── mod.ts

deno.json

{
  "imports": {
    "@deno/dnt": "jsr:@deno/[email protected]",
    "unist": "npm:@types/[email protected]"
  }
}

mod.ts

import type { Node } from "unist";

dnt.ts

import { build, emptyDir } from "@deno/dnt";

await emptyDir("./npm");

await build({
  entryPoints: ["./mod.ts"],
  outDir: "./npm",
  shims: {
    deno: true,
  },
  package: {
    name: "foo",
    version: Deno.args[0],
  },
  importMap: "deno.json",
});

Command

deno -A dnt.ts

Error log:

$ deno -A dnt.ts
[dnt] Transforming...
[dnt] Running npm install...

added 4 packages, and audited 5 packages in 3s

found 0 vulnerabilities
[dnt] Building project...
[dnt] Type checking ESM...
src/mod.ts:1:27 - error TS6137: Cannot import type declaration files. Consider importing 'unist' instead of '@types/unist'.

1 import type { Node } from "@types/unist";
                            ~~~~~~~~~~~~~~

error: Uncaught (in promise) Error: Had 1 diagnostics.
          throw new Error(`Had ${diagnostics.length} diagnostics.`);
                ^
    at getProgramAndMaybeTypeCheck (https://jsr.io/@deno/dnt/0.41.3/mod.ts:468:17)
    at build (https://jsr.io/@deno/dnt/0.41.3/mod.ts:354:17)
    at eventLoopTick (ext:core/01_core.js:177:7)
    at async file:///home/qz/dnt_import_issue/dnt.ts:5:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions