如何解决通过ES6导入导入commonJS模块,类型'typeof import
我有以下打字稿模块,
server.ts
// server.ts
import express from 'express';
const app = express();
module.exports = {
App: app,};
index.ts
// index.ts
import * as App from './server';
console.log(App.App);
在编译以下程序时,出现以下错误。 属性“ App”在类型“ typeof import(“ src / server”)”上不存在
从概念上讲为什么会失败?
特别令人困惑的是,仅打印导入的server.js之类的
// alternate server.ts
import * as App from './server';
console.log(App);
我在日志中得到了表达Express App结构的输出,如下所示
{
App: [Getter],default: {
App: [Function: app] EventEmitter {
emit: [Function: emit],addListener: [Function: addListener],on: [Function: addListener],...
get: [Function],notify: [Function],options: [Function],patch: [Function],post: [Function],...
listen: [Function: listen],request: [IncomingMessage],response: [ServerResponse],...
locals: [Object: null prototype],mountpath: '/',_router: [Function]
}
}
}
如果console.log的结构中存在该文件,为什么我无法通过代码访问该文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。