Getting an error when running the basic Express project - javascript

I'm messing around with Node.js for the first time and decided to create a simple application using express. I followed the instructions from github in an empty directory like so:
npm install -g express
express
npm install -d
node app.js
When navigating to localhost:3000 I get the follow error:
Express
500 Error: Cannot find module './lib/jade'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (C:\dev\gravity_kata\node_modules\jade\index.js:4:5)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
When looking under node_modules\jade\lib I see all of Jade's library files, but no jade folder. So I created a folder under lib called jade and moved the library files there and now my default application works.
Now, seeing as I have nearly no experience with Node.js and Express I'm pretty sure I did something wrong. Does anybody have any idea what is going on here?
Edit:
I dove into the Jade code. Under Jade's index.js file it requires lib\jade and looking under the lib folder, there was no jade.js file. Well, that is the problem, but why is the jade.js file missing? When pulling the Jade source from npm, there is a jade.js file under the lib directory. I copied the lib folder from the downloaded source into the Jade module for my project and it works fine now.
So for some reason, npm isn't pulling down the jade.js file. The version in the packages.json file match the source i pulled down, 0.21.0. Anybody have an idea on why this happened?

cd to your express project folder and run "npm install", this will install all dependencies

For me, on windows, jade version 0.22.0 fixed the issue.

it probably has to do with the fact, that you installed express globally (-g), but the npm install -d was done locally. try to install them both globally, or as i would prefer, both locally:
sudo npm uninstall express -g
npm install express
npm install jade (or npm install -d)

Really make sure that all the module requires are correct. Javascript is very funny about telling you what is actually wrong. Try removing the jade template line and see what happens then.

I just found this problem with the error of jade module. Looks like the jade folder was doesn't created automaticly (some kind of bug). Now i resolved this with reinstall jade. After that the jade folder was automaticly created.
use npm uninstall gulp-jade and then install gulp-jade again

Related

Error: Cannot find module 'loopback' in nodejs

I am facing below issue and unable to figure out the root cause.
Error: Cannot find module 'loopback'
Below are the dependencies I have in my package.json
"loopback": "^3.19.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^6.0.0",
"loopback-connector-postgresql": "^2.9.0"
First I did npm i and then node .
But it throws an error Cannot find module 'loopback'
Don't understand why this is behaving differently. Please suggest
Edit: My all modules are found under
> node_modules
> .staging
> //loopback modules and other modules are placed under .staging but not sure why.
The fact that your dependencies are inside the staging directory and not the main node_modules directory imply that something went wrong with the download/installation process and your dependencies are not installed properly. And hence you get the 'Could not find module' error.
Try the following steps -
Delete package-lock.json
Delete Node Modules folder
Do a npm install to install packages listed in package.json
Once the installation is complete, all your node dependencies should be inside your node_modules folder.
It might also be worth checking to see if you have more than one node version on your machine. That could cause similar problems as well.
use
npm config set user 0
npm config set unsafe-perm true
npm install -g loopback-cli
npm install
https://loopback.io/doc/en/lb3/

react-native, bundling failed

I am new to react-native and have found an error that makes absolutely no sense to me.
I am trying to include a calendar library: https://github.com/wix/react-native-calendars
I have included the dependency for that library in my package.json file and run npm install
The project was running fine and as expected. I have simply added one line of code to the project:
import { Calendar, CalendarList, Agenda } from 'react-native-calendars';
Nothing else. However now I am getting a red error message when the app loads on device and this is what my console is saying:
error: bundling failed: Error: While trying to resolve module xdate
from file
/Users/Alex/Documents/workspace/mobile/node_modules/react-native-calendars/src/index.js,
the package
/Users/Alex/Documents/workspace/mobile/node_modules/xdate/package.json
was successfully found. However, this package itself specifies a
main module field that could not be resolved
(/Users/Alex/Documents/workspace/mobile/node_modules/xdate/src/xdate.js.
Indeed, none of these files exist:
*
/Users/Alex/Documents/workspace/mobile/node_modules/xdate/src/xdate.js(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)
*
/Users/Alex/Documents/workspace/mobile/node_modules/xdate/src/xdate.js/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)
at ResolutionRequest.resolveDependency (/Users/Alex/Documents/workspace/mobile/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:103:15)
at DependencyGraph.resolveDependency (/Users/Alex/Documents/workspace/mobile/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)
at dependencies.map.relativePath (/Users/Alex/Documents/workspace/mobile/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)
at Array.map ()
at resolveDependencies (/Users/Alex/Documents/workspace/mobile/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)
at /Users/Alex/Documents/workspace/mobile/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33
at Generator.next ()
at step (/Users/Alex/Documents/workspace/mobile/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)
at /Users/Alex/Documents/workspace/mobile/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473
at
However I have checked in the directory and in fact /Users/Alex/Documents/workspace/mobile/node_modules/xdate/src/xdate.js does exist. However I do not see any of this part: (.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`
As to how /Users/Alex/Documents/workspace/mobile/node_modules/xdate/src/xdate.js/index can exist, that doesn't make sense because xdate.js is not a directory.
Any help?
It Usually happens if you try to install a module while your packager is open.
Try to delete node_modules folder and close the packager.
Then reinstall everything by npm install in your project directory.
First close your JavaScript bundler (Metro bundler in my case) and restart the application. This will create fresh dependency graph. This should solve the issue.
Just restart the bundler - no need to delete the Node Modules folder
I came across this issue when adding and using react-native-elements when using VS Code and Android Studio emulator on Linux Mint
In VS Code I had a terminal running Expo with Metro Bundler via 'npm start' command. After installing the react-native-elements in the folder (using 'npm install --save react-native-elements') and adding the import into the .js file I got the "However, this package itself specifies a main module field that could not be resolved" error.
In my case, this just involved a ^C in the terminal session to stop the Metro bundler and then running 'npm start' again. There was no need to delete the node modules folder at all.
If you're still getting the error even after deleting the ./node_modules folder and running npm install again, try doing the install with the --update-binary flag, i.e npm install --update-binary. This should clear out and rebuild any previously built packages on your machine.
Please don't delete the node modules folder.
The bundler has least to deal with node modules folder.
Instead close all the terminals. If using VS-code close that also.
Close all the local host server ports and if possible restart the system.
This might solve the issue.
If anyone have same issue, and remove node_module not working. Then you can try remove all node_module, package lock and using yarn to install node_module instead npm. Hope this help
None of the solutions above helped me except for restarting my MacBook. Wasted 30 minutes trying to fix this issue as I couldn't believe restarting my computer could be a solution.

Unable to create React.js project in WebStorm

I am going to create a React.js web application in WebStorm. I have installed create-react-app in /usr/local/bin and Node.js interpreter. I use Debian sid Linux distribution. When I try create project in WebStorm I receive this error:
/usr/bin/node /usr/local/bin/index.js .
module.js:538
throw err;
^
Error: Cannot find module '/usr/local/bin/index.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Done
I hope for help.
Try installing both node and create-reat-app globally by using -g flag in npm and make sure both are available system wide. To make node-interpreter available globally try setting default in nvm or try installing nodejs-legacy.
Anyways Web storm provides coding assistance depending on the file extension. Such as if it is a .jsx file then auto completion helps you in writing react specific syntax and enhanced ES syntax.
Also even after creating the project via Webstorm you have to install dependencies though npm install.
So my suggestion is instead of getting stuck just create a project using only create-react-app from the console by typing create-react-app
and then everything will be set for you. Test the set up by going inside the project folder and running npm start you could see basic react app open in your browser.
For further coding you can open your project folder inside web storm and continue with your project

Error: Cannot find module 'curl' at Function.Module._resolveFilename (module.js:489:15)

I installed node.js with the windows installer. The folder structure formed is C:\Program Files\nodejs\node_modules\npm\node_modules. The last node_modules has all the module folders I guess.
I use the node.js command prompt to execute my js script. When the script is on Desktop, it executes all fine. When I shift my script to another folder in my C: it gives the error. I don't want to give the absolute path as it will have to be changed again and again. Anyways, what path should I give as absolute to make it just work
Error: Cannot find module 'curl'
at Function.Module._resolveFilename (module.js:489:15)
I have gone through the resolutions mentioned in other discussions. Have made the NODE_PATH environment variable. Have edited PATH variable to make it C:\Program Files\nodejs and not C:\Program Files\nodejs\. Have executed npm install -g npm and nothing seems to work.
Sorry for the trouble, if anyone has already started looking into it. I found the solution. In the node.js command prompt, in the project folder I executed the following 'npm install curl' which downloaded the curl packages into a node_modules folder in the folder which has my script. I anyways wonder, then how it worked when I had placed my project on Desktop. It seems that the way node.js finds modules has to be checked. FYI - I have not set the NODE_PATH and the path still has C:\Program Files\nodejs\ after I freshly installed it. Thank you!

Can't properly install Meteor 0.6.1

I recently wanted to update to Meteor 0.6.1 from 0.5.4 and just did a meteor update in terminal. Immediately got an error in my terminal that gets thrown basically when I try anything.
/Volumes/Macintosh HD/Users/martijn/.meteor/meteor: line 35: cd: /Volumes/Macintosh: No such file or directory
module.js:340
throw err;
^
Error: Cannot find module '/Volumes/Macintosh HD/Users/martijn/tools/meteor.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
I removed all of Meteor for a complete reinstall:
rm /usr/local/bin/meteor
rm -rf /usr/local/meteor
curl https://install.meteor.com | /bin/sh
Same error when I try to create a Meteor project in my Sites directory. Can't figure out whats causing this, it used to work great in my Sites directory. The only way to avoid this error is to paste all the docs, examples, packages, scripts and tools folders into my /Volumes/Macintosh HD/Users/martijn/ directory along with my projects which is very messy.
Was thinking that it might have to do something with that I'm running two harddrives in my Macbook, an SSD for the OS and HDD for my documents. /usr/local/bin where meteor gets installed is on my SSD. This seems to me like something is off with the paths of the installation, any ideas?
Thanks
This seems to have been a bug in how we escape directory names. You hit this because your home directory has a space in it ("Macintosh HD"). I believe I fixed this just now, and the fix should be released in 0.6.2: https://github.com/meteor/meteor/commit/c059c384fdf9e7169f25cc36d86fbc0ed0a9da83
I had this same issue. Luckily I had another computer with Meteor where the upgrade worked. So here is what I did:
I noticed that usr/local/bin had very different files in the working and not working computer. So I just copied all the files from the working computer into the non-working one. Now meteor works on both. Not sure it's the best approach, but solved my issue. Meteor commands work once more.
Hope this helps,
Paul

Categories

Resources