我讨厌问这个问题,我想这是一个非常简单的设置或键入内容,缺少这个新项目。它会运行(via ts-node
)的事实告诉我,这只是VS Code抱怨(但是,为什么?)Google和SO搜索尚未发现任何具体的东西。
Visual Studio代码
版本1.22.2
提交3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9日期2018-04-12T16
:38:45.278Z
Shell 1.7.12
渲染器58.0.3029.110
节点7.9.0
体系结构x64
> node -v
v9.10.0
> npm -v
5.6.0
> tsc -v
Version 2.8.3
> npm ls --depth=0
[email protected] C:\...
+-- @types/[email protected]
+-- [email protected]
`-- [email protected]
> npm ls --depth=0 -g
C:\Users\...\AppData\Roaming\npm
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
我发现在这里提到的的TSDK设置偏好,设置和我保证打字稿被安装到本地node_modules
"typescript.tsdk": "node_modules\\typescript\\lib\\",
编辑它,错误会暂时消失,然后返回(如我想象的那样,VS正在刷新其缓存。)
tsconfig.json
{
"compilerOptions": {
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ ], /* Specify library files to be included in the compilation. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}
package.json
{
"name": "api-auth-test",
"version": "1.0.0",
"description": "",
"main": "app.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^9.6.6",
"axios": "~0.18.0",
"typescript": "^2.8.3"
},
"devDependencies": {}
}
您的tsconfiglib
缺少该es2015
条目,或者为空。
"lib": [
"dom",
"es2015"
],
删除es2015
给了我您遇到的错误。有关--lib选项的信息,请参阅tsconfig选项“ lib”的功能?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句