ts-loader 找不到 rxjs 7.0.1 的 index.d.ts
ts-loader does not find index.d.ts for rxjs 7.0.1
我有一个项目 TypeScript 项目并使用 RxJs。当 运行 构建时,这是对 webpack
的简单调用,我得到错误:
TS7016: Could not find a declaration file for module 'rxjs'. '<mypath>\node_modules\rxjs\index.js' implicitly has an 'any' type.
在与另一个可行的项目进行比较时,我注意到 RxJs 版本的差异:
- "rxjs": "^6.6.7" --> 有效
- "rxjs": "^7.0.1" --> 给出上述错误
原因似乎是最新版本确实没有 node_modules/rxjs
下的 index.d.ts 文件,而旧版本有。
我希望有人能告诉我该怎么做才能让新版本也编译。
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"
}
}
发生这种情况是因为您使用的是旧版本的 TypeScript。 RxJS 7 requires TS 4.2 or higher 并且在你的开发依赖中你有版本 ^3.8.3
.
我有一个项目 TypeScript 项目并使用 RxJs。当 运行 构建时,这是对 webpack
的简单调用,我得到错误:
TS7016: Could not find a declaration file for module 'rxjs'. '<mypath>\node_modules\rxjs\index.js' implicitly has an 'any' type.
在与另一个可行的项目进行比较时,我注意到 RxJs 版本的差异:
- "rxjs": "^6.6.7" --> 有效
- "rxjs": "^7.0.1" --> 给出上述错误
原因似乎是最新版本确实没有 node_modules/rxjs
下的 index.d.ts 文件,而旧版本有。
我希望有人能告诉我该怎么做才能让新版本也编译。
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"
}
}
发生这种情况是因为您使用的是旧版本的 TypeScript。 RxJS 7 requires TS 4.2 or higher 并且在你的开发依赖中你有版本 ^3.8.3
.