定义没有在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");
以下是链接:
- 将Json数据从服务器存储到Angular 2中的数组中
- 使用asynchronous和等待减less
- React本机应用程序无法在Android中启动,并在debugging版本上显示多条警告消息
- 包括TypeScript编译上下文中的app.component.ts
- TypeScripttypes损坏(错误TS2687):“迭代器”的所有声明必须具有相同的修饰符
- Typescript / NodeJS – 与工厂合作时的循环依赖
- 在子目录中debugging打字稿
- 如何在输出目录中使用TypeScript包含node_modules
- 如何使用Karma-Webpack使用Node Typescripttypes