Skip to content

TypeScript module "NodeNext" does not resolve index.d.ts from CJS modulesย #47848

Closed
@AndrewLeedham

Description

@AndrewLeedham

Bug Report

๐Ÿ”Ž Search Terms

NodeNext, esm, CJS, cli-spinners

๐Ÿ•— Version & Regression Information

  • This only occurs in nightly builds.
  • I was unable to test this on prior versions because nodenext is only supported in the nightly versions.

โฏ Playground Link

From what I can tell you can't install npm modules in the playground, so I made a repro on StackBlitz: https://stackblitz.com/edit/node-opvt9e?file=index.ts run npm run typecheck in the console to see the issue.

๐Ÿ’ป Code

import spinners from 'cli-spinners';

console.log(spinners);

๐Ÿ™ Actual behavior

TypeScript cannot find the typings for cli-spinners which is a CJS module. It does not use a main or exports or types field in the package.json, it just includes a index.js and index.d.ts file.

index.ts:1:22 - error TS2307: Cannot find module 'cli-spinners' or its corresponding type declarations.

1 import spinners from 'cli-spinners';
                       ~~~~~~~~~~~~~~


Found 1 error in index.ts:1

๐Ÿ™‚ Expected behavior

New NodeNext module behaviour to import CJS as it used to. E.g looking at index.d.ts if there is no main field. https://www.typescriptlang.org/docs/handbook/module-resolution.html#how-typescript-resolves-modules

๐Ÿ‘ช Related

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: ES ModulesThe issue relates to import/export style module behaviorFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions