I am using angular 13 and rxjs 7.4.0. and vscode......when I do this:
import { Observable } from 'rxjs';
I get this error:
Could not find a declaration file for module 'rxjs'. '/Applications/GenysisBuild/genysis-jta/node_modules/rxjs/dist/cjs/index.js' implicitly has an 'any' type.
Try `npm install @types/rxjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs';
Now this error has been popping up in prior versions with no clear solution. There is also the option to do this:
import { Observable } from 'rx'
and install this: @types/rx
then the error goes away but I really have no idea what 'rx' is relative to "rxjs"
can someone please clarify this issue?....how do I get rid of this error using "rxjs"?
EDIT: tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017", ....also tried 2015
"module": "es2020", ....also tried esnext
"lib": [
"es2020",
"dom"
],
"resolveJsonModule": true, ..with or without
"esModuleInterop": true ...with or without
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
also tried this:
"typeRoots": [
"node_modules/@types"
],
dist/cjs/index.js
when it should be going to src/index.ts
which points to src/internal/Observable.ts
. Could you please try importing from rxjs/index
and/or rxjs/internal/Observable
and confirm these files are present in node_modules/rxjs
? Most likely it's a configuration in your tsconfig.json
. You can uninstall the @types/rx
as the types are bundled with rxjs
. node_modules
directory and install everything from scratch. Couldn't find the root cause, but after some experimentation I've found that adding in tsconfig.json
the following lines seems to fix the issue on IntelliJ, with "typescript": "~4.8.4"
and "rxjs": "^7.8.0"
versions:
"target": "esnext",
"typeRoots": [
"./node_modules/@types",
"./node_modules/dist/types/operators/index.d.ts"
],
"paths": {
"rxjs": ["./node_modules/dist/esm/index"]
}