4
votes

I m actually studying TypeScript 1.5 and I was wondering can I import an external ES6 module ?

I need to use this one (which exposes an ES6 API) through my TS1.5 code (https://www.npmjs.com/package/rtts_assert).

Here's what I've tried :

import {rtts} from "../../node_modules/rtts_assert/es6/rtts_assert.es6";
import {rtts} from "../../node_modules/rtts_assert/es6/rtts_assert";
import * as rtts from "../../node_modules/rtts_assert/es6/rtts_assert.es6";
import * as rtts from "../../node_modules/rtts_assert/es6/rtts_assert";

But the transpiler (TypeScript > ES5, with CommonJS) doesn't find this module

Thanks for advance

1

1 Answers

0
votes

First, Importing from node_modules using relative paths seems very fishy for me. There should be a better solution. (Maybe import * as rtts from "rtts_assert/es6/rtts_assert.es6";?)

Secondly, if you wanna have ES5 code then you should use ES5 modules. Chrome may handle the ES6 module, but if you want your code to run in IE9 or similar then you must transpile the ES6 module to ES5. If you import a module then its code will be imported as is.