当前位置:  开发笔记 > 编程语言 > 正文

在nodejs typescript app中没有定义define

如何解决《在nodejstypescriptapp中没有定义define》经验,为你挑选了1个好方法。

我正在使用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

但是当我运行这个文件时,我得到的错误定义是没有定义的.

如果我有任何错误,请纠正我.

在此输入图像描述



1> C Snover..:

如果您正在编写一个纯粹在Node.js中运行的应用程序,那么在编译TypeScript文件时,您应该使用"commonjs"模块,而不是AMD模块.

如果您正在编写将在Node.js和浏览器中运行的应用程序,则在编译TypeScript文件时应该使用"umd"模块,而不是AMD模块.

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

推荐阅读
吻过彩虹的脸_378
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有