Cannot find module 'node-static' - javascript

I am trying to run samples regarding webrtc. For that I went to
https://bitbucket.org/webrtc/codelab/src/50a47bb092483fd7ca27998a365dff434919bf89?at=master
At step 5 I needed to run server.js. For that I opened my Windows Command prompt and entered:
C:\Program Files\nodejs>node D:\GITProjects\codelab\complete\step5\server.js
But I got this error:
module.js:338
throw err;
^ Error: Cannot find module 'node-static'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (D:\GITProjects\codelab\complete\step5\server.js:1:76)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
I have already installed node-static module and it is present at
"C:\Program Files\nodejs\node_modules\node-static"
Still I am getting the error "Cannot find module 'node-static'".
Environmental "PATH" variable is set to "C:\Users\user\AppData\Roaming\npm"
I can see the node-static folder is present at "C:\Users\user\AppData\Roaming\npm\node_modules\node-static" path too.
Edit:
Based on the comments I tried this on Windows Command Prompt to install node-static:
C:\Program Files\nodejs>npm install node-static -g
I got this as the output:
C:\Users\user\AppData\Roaming\npm\static -> C:\Users\user\AppData\Roaming\np
m\node_modules\node-static\bin\cli.js
node-static#0.7.6 C:\Users\user\AppData\Roaming\npm\node_modules\node-static
├── mime#1.3.4
├── colors#1.1.2
└── optimist#0.6.1 (wordwrap#0.0.3, minimist#0.0.10)
Can you help me location the cause of my issue?

node_static is not an inbuilt nodejs module so there should be a folder node_modules in your doc root folder(step5) with this module in it or create a package.json and list it as a dependency then run npm install before node server.js

just run npm install on cd into the "complete" directory i.e codelab\complete

Related

issue with React Scripts and terser-webpack-plugin

As of yesterday, I suddenly started getting this error when running the 'npm start' script in my create-react-app. I never had this issue before, and have not changed any configuration or package.json files in or out of react-scripts. terser-webpack-plugin is installed at the location and its "main" is:
"main": "dist/index.js",
I have tried reinstalling node_modules with no luck. I also tried the solution here: Use latest terser-webpack-plugin with Webpack5
throw err;
^
Error: Cannot find module 'Z:\Documents\chat-test\my-app\node_modules\terser-webpack-plugin\dist\index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (node:internal/modules/cjs/loader:353:19)
at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (Z:\Documents\chat-test\my-app\node_modules\react-scripts\config\webpack.config.js:18:22)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
path: 'Z:\\Documents\\chat-test\\my-app\\node_modules\\terser-webpack-plugin\\package.json',
requestPath: 'terser-webpack-plugin'
}
Possible fixes, try either or both:
npm i --save-dev terser-webpack-plugin
Remove package.lock and run npm i

Node JS Cannot find module 'node-properties-parser' Error while running as normal user in Amazon Linux

I have installed node-properties-parser globally by running npm install -g node-properties-parser as normal user(vaisakh). Then i ran my test.js file with the command node test.js now it's throwing the error
Error: Cannot find module 'node-properties-parser'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/data02/bamboo/test.js:3:12)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
I ran the above npm install -g node-properties-parser as root user and run the node test.js here it's working fine. But why it's throwing the error while running as normal user?
Thanks. Finally i found the answer, it's working when in run sudo npm install node-properties-parser without the -g option. But still i don't know why the -g option is not woking, in the docs it's given as install globally.

npm --> Err: Cannot find module 'readable-stream'

I have installed node js on my windows 10 machine, and the version is v4.4.2 but when I try to run npm install or even check npm version it throwing the following error. Any help would be greatly appreciated
Error: Cannot find module 'readable-stream'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\Users\nmadasu\AppData\Roaming\npm\node_modules\npm
\node_modules\are-we-there-yet\index.js:2:14)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
Also, after reading other solutions to this problem, npm install gulp -g, npm install 'readable-stream' or any other suggestion I read and tried did not work. It appears any command I try with npm throws the error below.
Error: Cannot find module 'readable-stream'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\Users\nmadasu\AppData\Roaming\npm\node_modules\npm
\node_modules\are-we-there-yet\index.js:2:14)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
I have also tried uninstalling node and reinstalling and same issue persists.
I figured it out, when I uninstalld I did not delete all the files. There were the node/npm files in my C: directory and failed to realize there were a bunch of npm module files in my / directory. So after uninstalling and deleting all related files I reinstalled node/npm and it is now working.
After all the checks its clear you need to uninstall and re-install node:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable // for stable version
sudo n 0.12.7 // for specific version like v0.12.7
// check the node version after install
node -v
If you are on windows make sure after you Uninstall node you %appdata% or C:\Users\admin\AppData\Roaming and delete all the npm folders that have been created here by your previous install.
git clone https://github.com/nodejs/readable-stream into global node_modules folder

Cannot find module 'sails'

I am trying to run a sails application with Webstorm 7.0.3.
this appear when i try to run the server in the console log:
module.js:340
throw err;
^
Error: Cannot find module 'sails'
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. (C:\Users**\projects\WebstormProjects**\app.js:2:1)
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 Module.runMain [as _onTimeout] (module.js:497:10)
Process finished with exit code 8
i installed sails globaly. i know that this is dont work because it cant find the sails module in the project's local 'node_modules' directory. if ill install again 'sails' localy it will work. but i dont want to...
Is there a way to make it work with sails global install? thanks!
The sails module that your code is looking for is not the same thing as the sails command you're executing at the terminal.
The command generates project skeletons. The module is the code that actually makes it run.
You need to install the command globally and the module locally.
Global installation (using npm install -g) does not make modules available globally to all node applications, it's only there for command line stuff.
If your applications relies on Sails, you should have it in your dependencies in package.json as well as installed locally.
If you don't like the way that npm creates a copy of each module locally, use yarn and tell it to symlink the cached version.

node.js require doesn't work in script?

I have a small node script named /tmp/test.js containing this:
console.log(require("w3cjs"));
If I do this from the command prompt:
nvm use v0.10.21
node /tmp/test.js
I get this output:
module.js:340
throw err;
^
Error: Cannot find module 'w3cjs'
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> (/tmp/test.js:1:75)
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)
But if I do this:
node -e $(cat /tmp/test.js)
I get this output:
{ validate: [Function: validate],
setW3cCheckUrl: [Function: setW3cCheckUrl],
w3cjs: [Circular] }
(In other words - it works.)
Why the difference and how do I make the script work?
When you run a script in a different directory, Node looks for local modules in the node_modules folder of that script's directory.
Suppose your shell's working directory is currently /projects/foo. When you run node /tmp/test.js, Node looks for modules in /tmp/node_modules, not in /projects/foo/node_modules.
However, if you don't run a script file, but run some text on the command line with -e, Node will check for a local module folder in your shell's current working directory, i.e., /projects/foo/node_modules.
It appears that you have w3cjs installed in your working directory, but not at /tmp. You should either install it there, or install the module globally with npm's -g option.

Categories