fix module.js:328 throw err; - javascript

I'm learning nodejs through some tutorials and so far it went smooth. Now I got an error and I'm stuck. Can anyone help me with it.
This is my app.js file
var greet5 = require('/greet5');
greet5.greet();
And this is my greet5.js file which is located in same directory as app.js
var greeting = "Hello from Revieling Module pattern";
function greet(){
console.log(greeting);
}
module.exports = {
greet : greet
}
when I run node app.js on terminal this is the error I'm facing.
module.js:328
throw err;
^
Error: Cannot find module '/greet5'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/pankaja/Nodejs/Tests/23-Module Patterns/app.js:19:14)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
Can anyone help me with this. Thanks

The README.md file of the nodejs project, appeared after running nodejs install, explains you how to run the web app through nodejs.
It says you have to execute npm run dev on the command line.
Here you are the default README.md:
# Front End Boilerplate
Front-end boilerplate for creating new web projects with Gulp.js and everything you need to get started.
# Getting Started
Required! Gulp installed `npm install -g gulp`
```
$ cd html-boilerplate
$ npm install
$ npm run dev
```
# Build to production
```
$ npm run build
```
Thank you for your suggestions!

Related

Heroku deployment failed - Please verify that the package.json has a valid "main" entry

I have created a simple React application that works locally, but for some reason, Heroku keeps giving me this error message when I try to deploy it. I have been googling for solutions and trying everything I can find, but this error still persists. I am still a beginner in this, and would gladly appreciate any help or advice. If anyone would like to try it, my repository which I am trying to deploy from is https://github.com/shittake/findabudbud. Thank you in advance.
-----> Build
Running build
> findabudbud#1.0.0 build
> react-scripts build
node:internal/modules/cjs/loader:361
throw err;
^
Error: Cannot find module '/tmp/build_2e0389cc/node_modules/fs-extra/lib/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. (/tmp/build_2e0389cc/node_modules/react-scripts/scripts/build.js:36:12)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
path: '/tmp/build_2e0389cc/node_modules/fs-extra/package.json',
requestPath: 'fs-extra'
}
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- node_modules checked into source control
https://devcenter.heroku.com/articles/node-best-practices#only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed

Cannot find module "serve-static" | JavaScript | node js

I want to create a simple server.js file in node.js which will act as a
local server.
I installed the connect module by the following command
npm install -g connect
And I can see the connect module inside node_modules
Then I tried to install serve-static module as follows
npm install -g serve-static
It says packages added but I can't see the module inside node_modules.
And when I try to run the following server.js it throws an exception saying
Cannot find module serve-static
server.js
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic("../angularjs"));
app.listen(5000);
Error
Error: Cannot find module 'serve-static'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Program Files\nodejs\server.js:2:16)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
1- Install them locally
npm install connect -S
npm install serve-static -S
2- OR Link them into your folder
npm link connect
npm link serve-static
3- OR Make sure that if the environment variable NODE_PATH is set correctly

GithubElectron: A JavaScript error occured in the browser process

I installed "electron-packager" using npm and executed the command
electron-packager . Johnston --platform=darwin --arch=x64 --version=0.36.0
And then I when I run the "Johnston.app", this error showed up (I didn't even see the main window)
Uncaught Exception: Error: Cannot find module 'electron'
at Function.Module._resolveFilename (module.js:332:15)
at Function.Module._load (module.js:282:25)
at Module.require (module.js:361:17)
at require (module.js:380:17)
at Object. (/Users/David/Github/Johnston/Johnston-darwin-x64/Johnston.app/Contents/Resources/app/main.js:3:18)
at Module._compile (module.js:426:26)
at Object.Module._extensions..js (module.js:444:10)
at Module.load (module.js:351:32)
at Function.Module._load (module.js:306:12)
at Object. (/Users/David/Github/Johnston/Johnston-darwin-x64/Johnston.app/Contents/Resources/atom.asar/browser/lib/init.js:104:10)
Is there any solutions? Thanks!
This likely has something to do with you having a different version of Electron installed on your machine that you are using to build with. In the folder for your app, run electron --version to get the version of electron that you have installed. Then, change the --version=0.36.0 to use whatever version you have installed.
If that doesn't fix it, then you should try rm -rf node_modules && npm install on your project. This will remove you node modules and then reinstall them all. If that doesn't work, please comment here and I will try to help again.

Cannot find module 'node-static'

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

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.

Categories