问题描述
我正在用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标志,但是无论如何都会显示此错误...
{
"compilerOptions": {
"module": "commonjs","esModuleInterop": true,"outDir": "./dist","target": "es6","lib": ["es5","es6"],"moduleResolution": "node","emitDecoratorMetadata": true,"experimentalDecorators": true
},"include": [
"./src/**/*"
]
}
感谢您的帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)