简体   繁体   English

Typescript + react-create-app 有快递问题

[英]Typescript + react-create-app with express problem

I'm new to Typescript, so I created a react-create-app project, the issue I have right know is that I want to connect a server with express.我是 Typescript 的新手,所以我创建了一个 react-create-app 项目,我知道的问题是我想用 express 连接服务器。

The thing is I create a folder -> src/server/server.ts问题是我创建了一个文件夹-> src/server/server.ts

so, react automatically creates a tsconfig.json which is:因此,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"]
}

I added the exclude part and created other tsconfig file我添加了排除部分并创建了其他 tsconfig 文件

tsconfig.server.json 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"
}

when I type in the command line tsc I want the server.ts to be compiled in the build folder in the root of my project but nonetheless is not working.当我输入命令行 tsc 时,我希望将 server.ts 编译到项目根目录的 build 文件夹中,但仍然无法正常工作。

it's simple doesn't do nothing.这很简单,什么都不做。

do you know what i'm doing wrong here?你知道我在这里做错了什么吗?

You need to use tsc --project --build to build, or if you are developing I would recommend you use tsc --project --watch which will re-compile every time a file has changed.您需要使用tsc --project --build来构建,或者如果您正在开发,我建议您使用tsc --project --watch每次文件更改时都会重新编译。

Full list of compiler options can be found here可以在此处找到编译器选项的完整列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM