Skip to content

Incompatible with node12 TypesScript module resolution #6641

Closed

Description

@demurgos

Bug Report

Current Behavior
I am trying out the upcoming TypeScript 4.5.0 version (currently in beta), and its new "moduleResolution": "node12".

With the following tsconfig.json:

{
  "compilerOptions": {
    "module": "node12",
    "moduleResolution": "node12",
    "target": "es2021",
    "noImplicitAny": true
  }
}

I get the following error when trying to import from "rxjs":

main.mts:1:28 - error TS7016: Could not find a declaration file for module 'rxjs'. '/data/projects/various/rxjs-ts-node12/node_modules/rxjs/dist/cjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/rxjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs';`

1 import { Observable } from "rxjs";
                             ~~~~~~


Found 1 error.

Expected behavior

The type declaration for rxjs should be resolved.

Reproduction

The tsconfig.json should be enough to reproduce the issue. Here is a repo set-up to reproduce the issue: https://github.com/demurgos/rxjs-ts-node12.

Environment

  • Runtime: Node 12+ (with ESM support)
  • RxJS version: 7.4.0
  • (If bug is related) Loader, build configuration: N/A

Possible Solution

Add a types field above node to the exports config in the package.json.

Additional context/Screenshots

Activity

  1. added a commit that references this issue on Oct 15, 2021
    935d033
  2. ievgennaida commented on Oct 16, 2021

    @ievgennaida

    Same problem when "module": "esnext" is used.
    RxJS version: 7.4.0
    Typescript 4.4.4

  3. demurgos commented on Oct 28, 2021

    @demurgos
    Author

    @benlesh @kwonoj
    I sent a patch in #6642 to fix this issue.
    Could you review it please?

    This issue is the main blocker preventing my projects from fully using true ESM.

  4. kwonoj commented on Oct 29, 2021

    @kwonoj
    Member

    I think we may need few internal try to understand some of behaviors.

    One of notable thing is rxjs does not support native esm yet. I'm not sure what's implication if we add this property for both of cases, if tsc try to import as native esm vs. other tooling's esm handling behavior such as tree shaking.

  5. added
    AGENDA ITEMFlagged for discussion at core team meetings
    on Oct 29, 2021
  6. kwonoj commented on Oct 29, 2021

    @kwonoj
    Member

    Peeking this bit more, there is specific concern from TSC's core team iteslf microsoft/TypeScript#46452.

    We will observe official release & discussion thread itself, along with some internal understandings how this'll affect across users of rxjs. Which means, we'll not try to make any immediate changes for now unfortunately.

  7. kwonoj commented on Nov 2, 2021

    @kwonoj
    Member

    See ref: #6642 (comment)

    In short, tsc will not enable this for the release (https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-rc/#beta-delta)

    If you try to use these settings in TypeScript 4.5 RC or stable, you’ll receive an error message directing you to use a nightly build instead

    Given we do not support our official release for non-release version of typescript, I do not think we'll going to have this until tsc gets finalized support for this feature.

    We'll keep follow latest upstream and will try to align with ecosystem but at this moment this issue better to be closed as no one knows later upstream tsc will have exact same way to support this or will there be breaking features.

    Please feel free to create new suggestions via discussions (https://github.com/ReactiveX/rxjs/discussions) for the feature request when tsc supports similar officially if needed.

  8. removed
    AGENDA ITEMFlagged for discussion at core team meetings
    on Nov 2, 2021
  9. lazy-coder-1 commented on Mar 18, 2022

    @lazy-coder-1

    The types need to be mentioned in tsconfig.json I guess.
    I have added this "./node_modules/rxjs/dist/types/**/*.d.ts" to "typeRoots". But still facing this issue.

  10. snawaz commented on Oct 2, 2022

    @snawaz

    I'm also facing the same issue (with "rxjs": "7.2.0") and I noticed lots of .ts files are under node_modules/rxjs/dist/types/. However, import { Observable } from "rxjs" fails with the same error as mentioned on the first post.

    My project tsconfig.json is this:

    {
      "compilerOptions": {
        "module": "commonjs",
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "lib": ["ES2019"],
        "target": "es2019",
        "sourceMap": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "incremental": true,
        "strict": true,
        "allowJs": true,
        "skipLibCheck": true,
        "jsx": "preserve"
      },
      "exclude": [
        "dist/**"
      ]
    }

    and

    $ node --version
    v14.19.1
    $ tsc --version 
    Version 4.1.3

    How do I fix this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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