Aral Roca Aral Roca - 4 months ago 50
AngularJS Question

Error: Cannot find module 'lodash' in angular-cli?

OS



Mac OSX El Capitan

Versions



angular-cli: 1.0.0-beta.8
,
node: 6.2.0
,
os: darwin x64


Description



I tried to add
lodash
library in angular-cli project:


  • npm install --save lodash

  • typings install lodash --global --save



Successfully installed in
node_modules
.

Answer

Change system-config.ts to:

const map: any = {
  'lodash': 'vendor/lodash',
};

const packages: any = {
  'lodash': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'index.js'
  }
};

And then import it as:

import 'lodash';
declare var _;

Finally use it as:

_.chunk();