定义没有在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");
以下是链接:
- angular2 – 通过使用路由器的问题
- 使用require()函数没有path
- Angular 4路由奇怪的行为:除非页面刷新,否则不呈现子模块
- 在TypeScript中导入Node.js npm模块(node_modules)和声明
- 由打字稿生成的定义文件(.d.ts)不能与package.jsontypes一起使用
- 如何为摩卡unit testing提供自定义错误消息的chai expect?
- 如何在@types上为范围/命名空间包安装TypeScript声明?
- 创buildPowerBI的自定义视觉时,无法在NodeJS中使用MomentJS
- 将内部的失败/拒绝传递给jQuery中的外部承诺,以避免代码重复