我正在使用typescript中的nodejs app,我在其中写了一个文件server.js作为fallow:
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')}!`); });
我使用gulp traspile生成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编译器的配置对象以使用{ module: "commonjs" }
或{ module: "umd" }
.