Cannot find module 'lodash/cloneDeep' while running ember server

#1

I can get a error like Cannot find module 'lodash/cloneDeep’

I can Run yarn to install dependencies and also i check the nodemodules we can find the lodash module

Kindly Help to resolve above issue.

0 Likes

#2

Do you have ember-auto-import installed?

0 Likes

#3

No…What happened i installed?

0 Likes

#4

Installing non-ember-aware modules from npm is pretty easy but it still requires either a bit of extra build config or using ember-auto-import (the preferred method). EAI is much easier to use and allows some cool stuff like lazy loading.

In summary: in order to import and use any arbitrary npm module in an ember app you’ll need ember-auto-import (recommended) or some custom build code.

0 Likes

#5

But in my case, i am already running yarn to install dependencies including lodash. Anyway i will try ember-auto-import. ] what ember-auto-import exactly do for me, because i am already included all dependencies.

0 Likes

#6

Including the dependency in your package requirements just ensures the dependency is installed in node_modules, it doesn’t do anything with the dependency once it’s there. When you build and Ember app (or any front-end webapp really) the build system has to be aware of what modules you want included in the final distributable code output and do any injection. An ember addon already has wiring that tells the build system what code needs to be included in the build output and how it should be linked to the resulting html page, but any arbitrary js module installed via yarn/npm does not. So ember-auto-import helps take those modules and introduce them to Ember’s build system. You could wire them into the build system manually instead but that’s more work.

TLDR: ember’s build system only knows about ember addons by default, other node modules like lodash/cloneDeep don’t know about ember and (most importantly) ember doesn’t know about them. Installing ember-auto-import introduces those modules to ember so it can inject them into the build.

2 Likes

#7

Thanks @dknutsen. I Will Try.

0 Likes