Problems with node. js cannot find Module xxx

Source: Internet
Author: User

Don't know why the first day of node. JS dry very smooth, back to the company after the dry point is not smooth, the main reason or the company's network problems, the use of restricted agents, can not directly use NPM from the remote download module, alas.

Node. JS's module load order is first looked up from the Node_modules folder under the project directory and then looked up at one level, you can use the node command under the project directory, and then enter Global.module.paths to view node. JS loads the module in the order.

Node JS installed by default will install NPM,NPM default module folder can use the command NPM root-g to view, or with NPM config get prefix to view, can also be modified by NPM config set prefix

Watch carefully and you will find a magical thing that NPM's default module installation location is not in node. JS Project within the scope of the default lookup, so we need to develop an environment variable Node_path to point to NPM's default module installation location.

Remember to write off the environment variable before it takes effect.

To summarize the reason for this problem is that there are 3

1. Writing errors, often the name of the module is wrong, resulting in a failure to load

2. No related modules installed

3. The relevant module is installed, but it is not set to global, and it is not in the Node_modules directory under the project root directory.

4. Node_path environment variable not set

Problems with node. js cannot find Module xxx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.