Search code examples
angularsystemjstypescript1.6

best solution for importing non-typescript npm modules


with ES6 using traceur and SystemJS this form is correct:

import _ from 'lodash';

for Typescript it is not enough - I get error error TS2307: Cannot find module 'lodash' So, I install 'lodash.d.ts' :

/// <reference path="lodash/lodash.d.ts" />
import _ from 'lodash';

Now, I get: Module '"lodash"' has no default export. from Typescript compiler

So, I try 'node style':

/// <reference path="lodash/lodash.d.ts" />
let _ = require('lodash');

I get: Uncaught (in promise) Error: require is not a function in browser

Finally:

import _ = require('lodash');

and it works but it's 'old form' not proper ES6.

Is there a single, proper way to use ES6 style Typescript import for non-typescript modules?

(Typescript 1.6.2)


Solution

  • Try import * as _ from 'lodash';