Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 正在获取错误属性'';不存在于类型';类型“…”&引用';_Node.js_Typescript_Gulp - Fatal编程技术网

Node.js 正在获取错误属性'';不存在于类型';类型“…”&引用';

Node.js 正在获取错误属性'';不存在于类型';类型“…”&引用';,node.js,typescript,gulp,Node.js,Typescript,Gulp,我正在使用typescript在NodeJS中开发一个应用程序,并在commonjs模式下使用gulp transpiler 我已将homeController.ts编写为: let homeController={ getIndex:(req,res)=>{ res.send('Hello world'); //Compiles the file named "index" in the views directory (`/views`) using the

我正在使用typescript在NodeJS中开发一个应用程序,并在commonjs模式下使用gulp transpiler

我已将homeController.ts编写为:

let homeController={
     getIndex:(req,res)=>{
        res.send('Hello world'); //Compiles the file named "index" in the views directory (`/views`) using the view engine (Jade).
    },
}
export default homeController;
我有一个单独的路由文件,名为route.ts

import  home  =require('../controller/homeController');
import express = require('express');

let router = express.Router();

router.get('/',home.getIndex);

module.exports = router;
并将其作为

import  routes = require('./routes/route');
并将其作为

app.use('/api', routes);
但是当gulp编译这些文件时,它会给出错误


如果我有任何错误,请更正。

您的homeController.ts文件导出的对象的形状为
{default:{getIndex:…}
。它没有顶级的
getIndex
属性


您可能希望使用
export=homeController
而不是
导出默认homeController
。它们不是等效的。

这有助于解决route.ts文件错误,但我仍然有server.ts文件错误