Node.js error:cannot Find module ' node-static ' ERROR resolution

Source: Internet
Author: User

Cannot find module problem

When testing WebRTC Codelab, run Codelab, complete, step1 error, throw error:

module.js:340
throw err;
^
Error:cannot Find module ' node-static '
At Function.module._resolvefilename (module.js:338:15)
At Function.module._load (module.js:280:25)
At Module.require (module.js:364:17)
At require (MODULE.JS:380:17)
At Object.<anonymous> (X:, Webprojects, Codelab, complete, step1, server.js:1:72)
At Module._compile (module.js:456:26)
At Object.module._extensions. JS (module.js:474:10)
At Module.load (module.js:356:32)
At Function.module._load (module.js:312:12)
At Function.Module.runMain (module.js:497:10)

See StackOverflow on someone's advice "$ npm install connect@2. x.x "$ npm Install serve-static" and so on, does not work here to give the right solution.

Why cannot find module problem occurred

First clear the default installation location for the global module:


$NPM root-g
X: Program Files, Nodejs, prefix, node_modules

Next, look at the default search path for the global module:

$node
> global.module.paths
[' X:,, Users, Admin, Repl, Node_modules ',
' X:,, Users, Admin, Node_modules ',
' X:,, Users, Node_modules ',
' X:,, Node_modules ']

It's no wonder that they don't intersect.

Nodejs path. png

Next, a breakpoint is found on the core-modules-sources/lib/module.js and the node.js is also searched by default for the global module from the following path:

["Y:,, Webprojects, Codelab, complete, Step1, node_modules", "Y:,, Webprojects, Codelab, complete, node_modules", "Y:,, Webprojects, Codelab, Node_modules", "Y:,, Webprojects, Node_modules", "Y:,, Node_modules", "X:,, Users, Admin, ,. Node_modules "," X:,, Users, Admin 、、. node_libraries "," Y:,, program Files, LIB, node "]


More confirmed my guess, the default search path does not include the default installation path for the module.

Solving cannot find module scheme

Then the solution is simple, you can add environment variable Node_path, point to the path that NPM root-g gives. You can also make a project-level variable on a webstorm project configuration:

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.