【发布时间】:2020-08-12 03:48:35
【问题描述】:
我是 Typescript 的新手,所以我创建了一个 react-create-app 项目,我知道的问题是我想用 express 连接服务器。
问题是我创建了一个文件夹 -> src/server/server.ts
所以,react 会自动创建一个 tsconfig.json,它是:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
],
"exclude": ["src/server"]
}
我添加了排除部分并创建了其他 tsconfig 文件
tsconfig.server.json
{
"compilerOptions": {
/* Basic Options */ /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ /* Concatenate and emit output to single file. */
"outDir": "./build", /* Redirect output structure to the directory. */
"rootDir": "./src/server", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
/* Strict Type-Checking Options */
"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'. */
/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"extends": "./tsconfig.json"
}
当我在命令行中输入 tsc 时,我希望将 server.ts 编译到项目根目录的 build 文件夹中,但仍然无法正常工作。
这很简单,什么都不做。
你知道我在这里做错了什么吗?
【问题讨论】:
标签: javascript node.js typescript express