我正在制作我的第一个typescript-node-express应用程序。
首先,我创建了自己的tsconfig文件,看起来像
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true,
"baseUrl": "./",
"outDir": "./build",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": true,
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modues"
]
}
}
在我的src / app.ts中,我正在初始化我的快递应用
import * as express from "express";
class App {
constructor() {
this.app = express();
}
//TODO: What is public app: express.Application
public app: express.Application;
}
const app = new App().app;
const port = 4040;
app.listen(port, function() {
console.log('Express server listening on port ' + port);
});
现在,当我执行ts-node ./src/app.ts时,出现以下错误
错误TS5023:未知的编译器选项'include'。
错误TS5023:未知的编译器选项'排除'。
at createTSError (/Users/an/.nvm/versions/node/v10.15.3/lib/node_modules/ts-node/src/index.ts:245:12) at reportTSError (/Users/an/.nvm/versions/node/v10.15.3/lib/node_modules/ts-node/src/index.ts:249:19) at Object.register (/Users/an/.nvm/versions/node/v10.15.3/lib/node_modules/ts-node/src/index.ts:260:36) at Object.<anonymous> (/Users/an/.nvm/versions/node/v10.15.3/lib/node_modules/ts-node/src/bin.ts:120:17) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)Unknown compiler
有人可以帮我弄清楚为什么我会收到此错误吗?
答案 0 :(得分:1)
根据the handbook,include
和exclude
应该是compilerOptions
的兄弟姐妹,而不是孩子:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true,
"baseUrl": "./",
"outDir": "./build",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": true,
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modues"
]
}
答案 1 :(得分:0)
问题是因为它们根本不属于编译器选项。
它们应与编译器选项一起存在,如下所示:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true,
"baseUrl": "./",
"outDir": "./build",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": true,
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modues"
]
}
在此处查看示例:https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#examples
答案 2 :(得分:0)
如果您在 100% 验证您的 exclude
或 include
选项不在 compilerOptions
范围内后仍然收到此错误,您可能忘记检查两者tsconfig.json
和 tsconfig.app.json
继承自前者。
值得花一些时间查看 official docs。