微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在用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/**/*"
]
}

感谢您的帮助

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。