4

When I try to use lodash in my angular applications (built from angular-seeds) it's returning '_' not defined but the lodash package is in my node_modules. What else do i need to do to include it?

6
  • Are you using any build tools? If so you may need to add the module to the build script. Otherwise just include the js file just like any other script tag <script src="/node_modules/lodash/dist/lodash.min.js"></script> Commented Jun 30, 2016 at 23:05
  • Your angular application executes in the browser. What the node_modules folder contains is irrelevant. angular-seeds seems to use bower for application dependencies. node modules are used by the tooling (karma, etc.) Commented Jun 30, 2016 at 23:06
  • @JBNizet It's being more and more common for people to ditch bower and use npm exclusively. Personally I prefer the set up you're describing (mainly because of how bower resolves conflicts), but it doesn't apply to everyone. Commented Jun 30, 2016 at 23:08
  • @jfadich But the fact is... that it applies to the OP. Commented Jul 1, 2016 at 5:57
  • @JBNizet telling OP mode modules are used by tooling doesn't help op load the node module that they are specifically trying to use. Commented Jul 1, 2016 at 5:59

3 Answers 3

5

The packages that you have installed using 'npm' are saved in node_modules that are used for server side whereas packages installed using 'bower' are saved in 'public/lib' folder. So the correct way to install lodash for angularjs is

bower install --save lodash
Sign up to request clarification or add additional context in comments.

Comments

0

Having lodash in your node_module doesn't do everything by itself. This problem usually occurs when you have not included the actual file. Add it to your index.

<script src="/node_modules/pathToYourLodash/lodash.js"></script>

Comments

0

I was missing an import _ from "lodash" statement from my page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.