定义没有在nodejs typescript应用程序中定义

我在打字稿中的nodejs应用程序,我已经写了一个文件server.js作为休闲:

import express = require('express'); import mongoose = require('mongoose'); let app=express(); app.set('port', process.env.PORT || 3000); // Set port to 3000 or the provided PORT variable /** * Start app */ app.listen(app.get('port'), function() { console.log(`App listening on port ${app.get('port')}!`); }); 

我已经使用了吞噬一切生成js文件

 define(["require", "exports", 'express'], function (require, exports, express) { var app = express(); app.set('port', process.env.PORT || 3000); // Set port to 3000 or the provided PORT variable /** * Start app */ app.listen(app.get('port'), function () { console.log("App listening on port " + app.get('port') + "!"); }); }); //# sourceMappingURL=../map/server.js.map 

但是当我运行这个文件得到错误定义是不是定义。

如果我犯了什么错误,请纠正我的错误。

在这里输入图像描述

如果您正在编写纯粹在Node.js中运行的应用程序,则在编译TypeScript文件时,应该使用“commonjs”模块,而不是AMD模块。

如果你正在编写一个在Node.js和浏览器中运行的应用程序,那么编译TypeScript文件时应该使用“umd”模块,而不是AMD模块。

因此,您需要更改您传递给Gulp TypeScript编译器的configuration对象,以使用{ module: "commonjs" }{ module: "umd" }

我想你在这里需要一个amd-loader ,一旦你安装了,你就可以使用require("amd-loader"); 在你的项目中。

 npm install amd-loader require("amd-loader"); 

以下是链接:

https://github.com/ajaxorg/node-amd-loader