Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with node12 TypesScript module resolution #6641

Closed
demurgos opened this issue Oct 15, 2021 · 7 comments
Closed

Incompatible with node12 TypesScript module resolution #6641

demurgos opened this issue Oct 15, 2021 · 7 comments

Comments

@demurgos
Copy link

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

demurgos added a commit to demurgos/rxjs that referenced this issue Oct 15, 2021
This commit adds `types` mapping for the package `exports`. It makes the package compatible with the upcoming `node12` module resolution in TypeScript 4.5.0.

Closes ReactiveX#6641
@ievgennaida
Copy link

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

@demurgos
Copy link
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.

@kwonoj
Copy link
Member

kwonoj commented Oct 29, 2021

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.

@kwonoj kwonoj added the AGENDA ITEM Flagged for discussion at core team meetings label Oct 29, 2021
@kwonoj
Copy link
Member

kwonoj commented Oct 29, 2021

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.

@kwonoj
Copy link
Member

kwonoj commented Nov 2, 2021

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.

@kwonoj kwonoj closed this as completed Nov 2, 2021
@kwonoj kwonoj removed the AGENDA ITEM Flagged for discussion at core team meetings label Nov 2, 2021
@lazy-coder-1
Copy link

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.

@snawaz
Copy link

snawaz commented Oct 2, 2022

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants