I'm getting an error when trying to use any global module, exemple:
Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Object.<anonymous> (C:\BitNami\wappstack\...\test\app.js) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10)
I installed the express command:
npm install -g express
My app.js:
var express = require('express');
And run it using windows powershell or node.js command prompt windows:
node app.js
do not really know what's going wrong, I read something about environment variables in windows, can this be?
The problem was: Windows environment variables was not configured for npm folder. Search for your npm folder and add the path in the environment variables.
If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.
To fix Cannot find module errors, install the modules properly by running a npm install command in the appropriate directory as your project's app. js or index. js file. or delete the node_modules folder and package-lock.
To solve the error "Cannot find module 'express'", install the package by running the command npm install express in the root directory of your project. If you don't have a package. json file, create one by running npm init -y . The error occurs when we try to import the express package without installing it.
Just to quote from here:
https://www.npmjs.org/doc/files/npm-folders.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With