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: