Search code examples
angularlodashangular5angular2-aotaot

Import single lodash functions for libraries with aot


I'm trying to use lodash with the syntax "import * as includes from 'lodash.includes';" so i don't need to install all lodash library and just the functions that I need. Everything works fine but aot. I build my library to use it in other project as a node_modules and when I do ng serve everything works fine but when doing ng serve --aot I got: "Module not found: Error: Can't resolve 'lodash.includes' in etc...". I could solve the problem by installing lodash in my library project and use it with the syntax "import * as _ from 'lodash';" but I'd like to have only the dependencies that I need not the whole lodash library. Any guess?


Solution

  • If you don't want to include the entire Lodash library in your Angular project, then you need to use the lodash-es library as a dependency instead of the normal lodash library as a dependency. Just change it in your package.json file and then in each of your references within your project to point to that library instead.