【发布时间】:2015-07-17 07:03:19
【问题描述】:
鉴于提供的语法 here(带有导入/导出的标准 ES6 模块)和下面的文件,typescript 编译器 (tsc) 构建的文件在与 NodeJS 一起使用时将抛出 Error: Cannot find module。
这是一个精简的例子:
输入文件
src/main.ts
import {Example} from 'example';
let e = new Example();
src/example.ts
export class Example {}
编译
注意,使用来自 Windows 机器的 npm install -g typescript 版本 1.5.0-beta 的 tsc。
tsc --rootDir src --outDir bin
输出文件
bin/main.js
var example_1 = require('example');
var e = new example_1.Example();
bin/example.js
var Example = (function () {
function Example() {
}
return Example;
})();
exports.Example = Example;
我做错了吗?我希望 main.js 包含类似 require('example.js') 的内容。
【问题讨论】:
标签: javascript node.js typescript ecmascript-6