typescriptを使用してプロジェクトを再構築しようとしました。 私が使用して作業バージョンを作成することができた様々な試みの後:tsconfig.jsonの「モジュールをcommonjs」module = systemを使用してノード用TypeScriptを設定していません
私はシステムを使用することを好むだろう - しかし、私はsystemjs
でそれを設定することができませんでしたboot.ts
import {AppServer} from './app';
var _appServer = new AppServer();
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
app.ts tsconfig.jsonに "module": "system"
を使用して
/// <reference path="typings/restify/restify.d.ts" />
import {Server, Response, Request, createServer} from 'restify';
export class AppServer {
private server: Server;
constructor() {
this.init();
}
init() {
this.server = createServer();
this.server.get('/hello/:name', this.respond);
this.server.listen(8080,() => {
console.log('%s listening at %s', this.server.name, this.server.url);
});
}
respond(req: Request, res: Response, next: Function) {
res.send('hello ' + req.params.name);
next();
}
}
、私は(boot.tsでさえimport System = require('systemjs')
と)次の出力を得る:
➜ server git:(master) ✗ npm run server
> [email protected] server /Users/maquh/Development/02_Backgular/server
> node boot.js
/Users/maquh/Development/02_Backgular/server/boot.js:1
(function (exports, require, module, __filename, __dirname) { System.register(['./app'], function(exports_1) {
^
ReferenceError: System is not defined
at Object.<anonymous> (/Users/maquh/Development/02_Backgular/server/boot.js:1:63)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:138:18)
at node.js:974:3
Transpiledブートを.js
System.register(['./app'], function(exports_1) {
var app_1;
var _appServer;
return {
setters:[
function (app_1_1) {
app_1 = app_1_1;
}],
execute: function() {
//System.import('./app.ts').
_appServer = new app_1.AppServer();
}
}
});
//# sourceMappingURL=boot.js.map
UPDATE: 私もboot.ts
var System = require('systemjs');
System.transpiler = 'ts';
System.import('./app.js').then(function(m) {
console.log(m);
}, function(err) {
console.error(err);
});
次のエラーにそれらのリードの別の代替バージョンを試してみました:
[Error: ENOENT: no such file or directory, open '/Users/markusbellgardt/Development/02_Backgular/server/restify']
問題はなんですか?あなたができなかったことをどうやって知っていますか? – Pablo
端末出力を – Maquh
にしました。 'boot.ts'を表示していますが、' boot.js'からクラッシュしているように見える行は表示されません。 'boot.js'のディスク内容(コンパイルされた出力)を表示できますか? – Claies