您能帮助我了解此Typescript-compiler错误吗?

时间:2020-11-11 21:31:03

标签: node.js typescript koa tsc

我正在用koa和打字稿构建一个小型应用程序,这是我的index.ts文件:

import Koa from 'koa';
import urlMiddleware from './middlewares/url';

const app = new Koa();

app.use(urlMiddleware);

app.listen(3000);

运行命令tsc --watch src/index.ts后,出现此错误:

[10:21:41 PM] Starting compilation in watch mode...

src/index.ts:1:8 - error TS1259: Module 
'"/mnt/c/Users/maxim/dev/streaming/node_modules/@types/koa/index"' can only be default-imported using 
the 'esModuleInterop' flag

1 import Koa from 'koa';
         ~~~

  node_modules/@types/koa/index.d.ts:730:1
    730 export = Application;
        ~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when 
using the 'esModuleInterop' flag.

[10:21:44 PM] Found 1 error. Watching for file changes.

显然,打字稿编译器不喜欢在我的代码中导入Koa的方式,因此我也尝试使用esModuleInterop标志,但是无论如何都会显示此错误...

这是我的tsconfig.json文件:

{
"compilerOptions": {
  "module": "commonjs",
  "esModuleInterop": true,
  "outDir": "./dist",
  "target": "es6",
  "lib": ["es5", "es6"],
  "moduleResolution": "node",
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true
},
"include": [
  "./src/**/*"
]
}

感谢您的帮助

0 个答案:

没有答案