升级到 TSC 2.0.0 - VS Code 语法检查器未解析节点模块
Upgraded to TSC 2.0.0- node modules aren't resolved by VS Code syntax checker
问题
- 导入 NPM 模块时,VS Code 无法显示有关 NPM 模块的导入信息。
[TS] Cannot find module 'lodash'/'react'/'etc'.
- 当导入一个用 TypeScript 编写的 NPM 模块时(或者
typings
属性 在其 package.json
中)我没有看到这个问题。
- WebPack 仍然可以正常编译,这让我相信这是 VS Code 或 Typings 工具的问题。
设置
我今天早上 运行 tsc
1.8。我后来升级到 tsc
2.0.0。
VS 代码 1.4.0 6276dcb0ae497766056b4c09ea75be1d76a8b679
节点 5.10.0
tsc -v
: === "Version 2.0.0"
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "react",
"experimentalDecorators": true,
"noImplicitAny": false,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"strictNullChecks": true
},
"exclude": [
"node_modules"
],
"compileOnSave": false,
"buildOnSave": false
}
完整项目源代码here。免责声明:这是一个相当大的代码库。
我可以通过将以下内容添加到 /.vscode/settings.json
来解决问题:
{
"typescript.tsdk": "node_modules/typescript/lib",
}
问题
- 导入 NPM 模块时,VS Code 无法显示有关 NPM 模块的导入信息。
[TS] Cannot find module 'lodash'/'react'/'etc'.
- 当导入一个用 TypeScript 编写的 NPM 模块时(或者
typings
属性 在其package.json
中)我没有看到这个问题。 - WebPack 仍然可以正常编译,这让我相信这是 VS Code 或 Typings 工具的问题。
设置
我今天早上 运行 tsc
1.8。我后来升级到 tsc
2.0.0。
VS 代码 1.4.0 6276dcb0ae497766056b4c09ea75be1d76a8b679
节点 5.10.0
tsc -v
: === "Version 2.0.0"
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "react",
"experimentalDecorators": true,
"noImplicitAny": false,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"strictNullChecks": true
},
"exclude": [
"node_modules"
],
"compileOnSave": false,
"buildOnSave": false
}
完整项目源代码here。免责声明:这是一个相当大的代码库。
我可以通过将以下内容添加到 /.vscode/settings.json
来解决问题:
{
"typescript.tsdk": "node_modules/typescript/lib",
}