Skip to content

Wrong nodejs import path when generating declaration  #42137

Closed
@dbellavista

Description

@dbellavista

Bug Report

🔎 Search Terms

  • File '@types/node/events.d.ts' is not a module.
  • import from "node/events"
  • require("node/events")

🕗 Version & Regression Information

  • I was unable to test this on prior versions because versions before 4.0 are unable to generate the correct type definition

⏯ Repo Link and Code

Sorry I could't use the playground since I need typings for nodejs.

npm install
npx tsc -p jsconfig.json
npx tsc -p noemit.jsconfig.json

🙁 Actual behavior

The generated definitions is

export class Issue extends EventEmitter {
}
import { Writable } from "node/stream";
import EventEmitter = require("node/events");
export { Writable };

which causes the errors:

issue.d.ts:3:26 - error TS2306: File '/home/me/issue/node_modules/@types/node/stream.d.ts' is not a module.

3 import { Writable } from "node/stream";
                           ~~~~~~~~~~~~~

issue.d.ts:4:31 - error TS2306: File '/home/me/issue/node_modules/@types/node/events.d.ts' is not a module.

4 import EventEmitter = require("node/events");

🙂 Expected behavior

The correct definition file should be

export class Issue extends EventEmitter {
}
import { Writable } from "stream";
import EventEmitter = require("events");
export { Writable };

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions