Skip to content

Module resolution: Setting target to ES6 and higher results in numerous TS2792: Cannot find module 'undici-types' errors #61877

Open
@SetTrend

Description

@SetTrend

Demo Repo

https://github.com/SetTrend/typescript_modres_mre

Which of the following problems are you reporting?

Something else more complicated which I'll explain in more detail

Demonstrate the defect described above with a code sample.

With following TypeScript configuration set, TSC throws numerous error TS2792: Cannot find module 'undici-types' compile time build errors.

tsconfig.json

{
  "include":
  [
    "*.*ts"
  ],
  "compilerOptions":
  {
    "target": "esnext",
    "strict": true,
    "noEmitOnError": true,
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "sourceMap": true
  }
}

Node.js version

> node --version
v22.15.0

npm version

> npm --version
11.4.2

Run tsc --showConfig and paste its output here

{
    "compilerOptions": {
        "target": "esnext",
        "strict": true,
        "noEmitOnError": true,
        "noImplicitAny": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "sourceMap": true,
        "module": "es6",
        "moduleResolution": "classic",
        "useDefineForClassFields": true,
        "noImplicitThis": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,
        "strictBuiltinIteratorReturn": true,
        "alwaysStrict": true,
        "useUnknownInCatchVariables": true
    },
    "files": [
        "./index.ts"
    ],
    "include": [
        "*.*ts"
    ]
}

Run tsc --traceResolution and paste its output here

It's all in the MRE.

Paste the package.json of the importing module, if it exists

{
  "name": "webpacktest",
  "version": "1.0.0",
  "main": "index.js",
  "scripts":
  {
    "build": "npx tsc"
  },
  "author": "SetTrend",
  "license": "ISC",
  "description": "",
  "devDependencies":
  {
    "ts-loader": "^9.5.2",
    "typescript": "^5.8.3",
    "webpack": "^5.99.9",
    "webpack-cli": "^6.0.1"
  }
}

Paste the package.json of the target module, if it exists

It's all in the MRE.

Any other comments can go here

It's all in the MRE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions