Skip to content

noUnresolvedImports: cannot resolve named exports from packages using export = in @types definitions (@types/react, @types/lodash) #9626

@jthrilly

Description

@jthrilly

Environment information

CLI:
  Version:                      2.4.9

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  JS_RUNTIME_VERSION:           v24.11.1
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         pnpm/10.18.2

What happened?

noUnresolvedImports reports false positives for named exports from packages whose @types definitions use export = Namespace (CJS-style namespace exports). This affects widely used packages including react and lodash.

Example error:

app.tsx:1:10 lint/correctness/noUnresolvedImports

  × The module react has no export named useState.

  > 1 │ import { useState } from "react";
      │          ^^^^^^^^

Root cause

When @types/react is installed, Biome prefers reading @types/react/index.d.ts over react/index.js for export resolution (likely due to PR #9267 which "Added preference for `types`/`typings` over `main` in package.json resolution").

@types/react/index.d.ts uses export = React — TypeScript's CJS interop syntax for namespaced exports. Biome cannot resolve individual named imports (useState, useCallback, etc.) from this pattern.

Removing @types/react from node_modules eliminates all false positives. Restoring it brings them back.

The same issue affects @types/lodash (which also uses export =).

Minimal reproduction

mkdir repro && cd repro
pnpm init
pnpm add react @types/react @biomejs/biome
cat > biome.json << 'EOF'
{ "linter": { "enabled": true, "domains": { "project": "all" } } }
EOF
echo 'import { useState } from "react"; export const x = useState;' > app.tsx
npx biome check app.tsx  # ERROR: The module react has no export named useState.
pnpm remove @types/react
npx biome check app.tsx  # No error

Expected result

noUnresolvedImports should correctly resolve named exports from the export = React pattern in .d.ts files, or fall back to the runtime module when the type declarations use this pattern.

Metadata

Metadata

Assignees

Labels

A-CoreArea: coreA-ResolverArea: resolverL-JavaScriptLanguage: JavaScript and super languagesS-Bug-confirmedStatus: report has been confirmed as a valid bug

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions