javascript - 使用 TypeScript 构建 RESTful API 时出现“系统未定义”
问题描述
我正在尝试使用 TypeScript 和 SystemJS 构建 RESTful API
// index.ts
// Import express
import express from "express"
// Imports routes
import apiRoutes from "api-routes.js"
// Initialise the app
const app = express()
// set up server port
const port = process.env.port || 3000
// Send message for default URL
app.get('/', (request, response) => response.send('Hello World with Express.'))
// Launch app to listen to specified port
app.listen(port, function(){
console.log(`Listening on port ${port}`)
})
// Use API routes in the app.
app.use('/api', apiRoutes)
该文件被编译为 javascript
System.register(["express", "api-routes.js"], function (exports_1, context_1) {
"use strict";
var express_1, api_routes_js_1, app, port;
var __moduleName = context_1 && context_1.id;
return {
setters: [
function (express_1_1) {
express_1 = express_1_1;
},
function (api_routes_js_1_1) {
api_routes_js_1 = api_routes_js_1_1;
}
],
execute: function () {
// import * as express from "express"
// import * apiRoutes from './build/'
// Initialise the app
app = express_1.default();
// set up server port
port = process.env.port || 3000;
// Send message for default URL
app.get('/', function (request, response) { return response.send('Hello World with Express.'); });
// Launch app to listen to specified port
app.listen(port, function () {
console.log("Listening on port " + port);
});
// Use API routes in the app.
app.use('/api', api_routes_js_1.default);
}
};
});
我收到以下错误
它说我无法system
从系统模块中引用。这是我的仓库的链接
在html
我像这样导入 SystemJS
<script src="node_modules/systemjs/dist/system.js"></script>
如何在我的index.ts
文件中导入 SystemJS?
解决方案
推荐阅读
- android - 在Android中添加后警报响起
- ios - 斯威夫特:UISlider轨道的一侧不圆
- sql - 查询之间的区别
- python - Python 升级图像(没有外部库帮助)
- c# - 通过菜单c#打开和关闭表单
- python - TkInter 错误:没有显示名称和 $DISPLAY 环境变量
- android - 如何从在线下载视频并将其存储在本地设备上,然后使用视频播放器在 Flutter 应用程序上播放视频?
- c# - 是否使用 System.Security.Cryptography.RSACng 来签名和验证数据线程安全?
- python - 将表列和值转换为嵌套 JSON
- angular - Angular - 可安装性“未检测到匹配的服务人员”