0

After installing packages e.g. lodash using npm install --save lodash, I am trying to add it to the top of the file.

import _ from 'lodash';

console.log(add(10, 3));

When I start Live Server from VS Code, I get this error. I cannot figure it out how to fix it? Please help me:

Uncaught TypeError: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../".

I am trying to write the path in different ways, but it did not help me.

4
  • 1
    Please don't post images of code. Include them in your post as text. Commented Feb 1, 2023 at 19:50
  • Also please share the output of npm -v and the project structure, and dependency.json file contents here Commented Feb 1, 2023 at 20:00
  • 1
    Have you tried loading from the node_modules directory? If you are using a raw module and you did not bundle your code yet e.g. WebPack, you will have to change the import to something like: import _ from '../node_modules/lodash' Commented Feb 1, 2023 at 20:03
  • As I understand I cannot use import without any bundler like parcel or webpack ? I am trying to write this way like yo say '../node_modules/lodash' - but it does not work I add my js file to html with type="module" and I thought I can add lodash without ant bundler. Npm - v =8.19.3: json file include lodash Commented Feb 2, 2023 at 17:06

1 Answer 1

1

You can call any method by using _. Example:

console.log(_.add(10, 3));
Sign up to request clarification or add additional context in comments.

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.