Search code examples
webpackrxjsts-loader

ts-loader does not find index.d.ts for rxjs 7.0.1


I have a project TypeScript project and use RxJs. When running the build, which is a simple call to webpack I get the error:

TS7016: Could not find a declaration file for module 'rxjs'. '<mypath>\node_modules\rxjs\index.js' implicitly has an 'any' type.

When comparing to another project that works I noticed the difference in the RxJs version:

  • "rxjs": "^6.6.7" --> works
  • "rxjs": "^7.0.1" --> gives the above error

The reason seems to be that the latest version indeed does not have an index.d.ts file under node_modules/rxjs whereas the old version has.

I hope, someone can tell what to do in order to get the new version compiling too.

Package.json

{
    "name": "calculator-browser",
    "version": "1.0.0",
    "description": "",
    "main": "src/index.ts",
    "scripts": {
        "serve": "webpack-dev-server",
        "build": "webpack && copyfiles -f src/index.html public",
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "prettier": {
        "tabWidth": 4,
        "useTabs": true
    },
    "repository": {
        "type": "git",
        "url": "git+https://github.com/JohannesSchacht/calculatorBrowser.git"
    },
    "author": "",
    "license": "ISC",
    "homepage": "https://sch-8.de",
    "devDependencies": {
        "copyfiles": "^2.4.1",
        "ts-loader": "^6.2.2",
        "typescript": "^3.8.3",
        "webpack": "^4.42.1",
        "webpack-cli": "^3.3.11",
        "webpack-dev-server": "^3.10.3"
    },
    "dependencies": {
        "immer": "^9.0.2",
        "redux": "^4.1.0",
        "rxjs": "^6.6.7"
    }
}


Solution

  • This is happening because you are using an old version of TypeScript. RxJS 7 requires TS 4.2 or higher and in your dev-dependencies you have version ^3.8.3.