编译成CommonJS不会产生NodeJS可用的文件
给定这里提供的语法(标准的ES6模块导入/导出),以及下面的文件,打字稿编译器(TSC)build立文件,将抛出Error: Cannot find module
时使用NodeJS。
这是一个简单的例子:
input文件
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
输出文件
斌/ main.js
var example_1 = require('example'); var e = new example_1.Example();
斌/ example.js
var Example = (function () { function Example() { } return Example; })(); exports.Example = Example;
我做错了什么吗? 我期望main.js
包含类似require('example.js')
东西。
import {Example} from 'example';
您正在导入模块,而不是文件。 尝试
import {Example} from './example';
- 如何让TypeScript编译器不发出目录结构
- es6模块到commonjs节点和谐旗下的打字稿
- 如何从其他js文件扩展类而不需要声明文件
- 使用requirejs加载一个带有几个类的文件(grunt-concat)
- asynchronous摩卡testing(与Chai断言库)应该失败,但被标记为通过
- 有没有一种方法可以在REST API中访问Express的应用程序?
- 将“this”传递给构造函数中的类variables
- Typescript / NodeJS – 与工厂合作时的循环依赖
- 当使用angular version 2.4.9,typescript&webpack version 2.2.1时,属性'map'在types'Observable <Response>'上不存在