[英]Typescript + react-create-app with express problem
我是 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 文件夾中,但仍然無法正常工作。
這很簡單,什么都不做。
你知道我在這里做錯了什么嗎?
您需要使用tsc --project --build
來構建,或者如果您正在開發,我建議您使用tsc --project --watch
每次文件更改時都會重新編譯。
可以在此處找到編譯器選項的完整列表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.