Using Lodash with Ionic 2

Florian Hirsch
Feb 4, 2017 · 1 min read

I just started my first Ionic 2 application and struggled with adding Lodash as dependency. Since TypeScript 2 adding npm dependencies should be that easy:

npm install --save @types/lodash

You don’t have to deal with other tools like typings anymore. However the next build failed with this transpile error:

[12:06:18] transpile started …
[12:06:44] typescript: node_modules/@types/lodash/index.d.ts, line: 11444
‘]’ expected.

The problem is that the current version of the declaration file expects TypeScript 2.1 whereas Ionic 2 is using TypeScript 2.0. You need to search for a matching version and install the correct one:

npm view @types/lodash # check the dist-tags
npm install --save --save-exact @types/lodash@ts2.0

Don’t forget the save-exact flag. Otherwise your coworkers will run in the same problem after fetching.

Florian Hirsch

Written by

developer at finanzguru.de

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade