0

To run my practice JS files I have used Node so for example I say node bts.js . I needed a queue data structure so I installed Collections using npm install collections --save and also seen in picture it does show in the hierarchy.

Then in my JS file I said const Deque = require('./collections/deque'); and then later I wanted to use it like const dq = new Deque(); but I get the 'MODULE_NOT_FOUND' error. But why? I have attached the screen shot if my structure too.

enter image description here

1
  • 1
    As is stated in the docs, you need: var Deque = require("collections/deque"); (since collections is a module, not a script in your main folder)` Commented Jul 20, 2020 at 11:33

1 Answer 1

1

You're trying to import an external module (installed in node_modules) with a relative path - ./collections/deque. This will look in local folder in your source code named collections and try to find a file named deque.js inside of it. Since it does not exist, you get the module not found error.

You have to import the dependency from node_moduels as:

const Deque = require("collections/deque"); // see the missing ./ at the start of the path
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.