Cannot find module 'express' on nodejs.log - node.js

I have a react and nodejs project on the host 'O2Switch'.
My React seems to work fine, but there is a whitepage on my url https://www.desmettre-maxime-canin.com/ because of my node not respond. On localhost, it's good.
In my nodejs.log file, i have the error "Cannot find module 'express' on nodejs.log"
How to fix this please ??? The module is correctly installed on my node_modules, good in package.json etc.
I tried a million time to re-install express in a million ways...
Thank you

Hello first check again if you installed express via npm in root directory of your project.Some users had same problem and used this command and worked
npm install express --save
or install a specific express version
npm install express#4.18.1
Also try to remove node_modules and package.json file,clear npm cache ,maybe you did it many times and accidentaly you created errors.And after that try again to install npm depedencies
rm-rf node_modules package-lock.json
npm clean cache --force
npm init
Finally try to fix node_path environment variable,if your node_modules is in another directory
set NODE_PATH=your\directory\to\node_modules;%NODE_PATH%
I am not sure but installing many times express may caused this problem,you can check this by creating new project with clean install of npm packages.

Related

npm "Invalid response body while trying to fetch". Can't install any dependencies using npm

Good day everyone! I recently got this message:
npm WARN config global --global, --local are deprecated. Use --location=global instead
I took care of this problem by editing the 4 necessary files (npm, npm.cmd, npx, npx.cmd).
Problem is, now I can't install any dependency and I can't use npx (for example for npx create-react-app my-app).
When trying to install a dependency
Running npx
What I have tried so far:
npm cache clean –force
npm chache verify
Deleted the npm-cache folder under 'C:\Users\reaga\AppData\Local\
Completely uninstalled Nodejs and reinstalled the LTS
Completely uninstalled Nodejs and reinstalled the current version
Changed the npm-cache folder's location using npm config set cache C:\reaga\nodejs\npm-cache --global
Deactivated antivirus
Prayed to 17 different gods
On the flip side yarn seems to be working so I have no problems running yarn add express for example. Any help would be very much appreciated!

Whenever I try to run my server via Heroku I get "Error: Cannot find module 'dotenv'"

Browsing stack overflow, I noticed that a common fix is make sure that dotenv is in dependencies and not just devDependencies. Here's a screenshot of the log and the package.json. You'll notice that dotenv is indeed in my dependencies. I also deleted and reinstalled node_modules multiple times but still no luck.
I am requiring the dotenv at the top of my server file as shown here
I fixed the issue. I decided to try uninstalling dotenv and reinstalling, this worked. Apparently, this was different from deleting node modules and npm install.
I see dotenv is added to a devDependency: devDependency are special and are only installed when you do a npm install on the package.json which contains them. Usually, you'll add your development tooling (like test runners, etc.) in devDependencies since they are not required for the application to run.
When we run an application in production, we install dependencies using npm install --production which only installs the dependencies mentioned in the dependencies section of package.json. This is also what Heroku does for you (check their buildpack for Node.js!)
To install a devDependency, you would do: npm i -D <package name>; and to install a production dependency (like your web framework like express), you'd do npm i -S express.
Try running npm i -D dotenv and check if it works (it may also work if you just do a npm i dotenv.

Cannot uninstall webpack from react-script

I was trying to make a todo-app in react, which is new to me. But after once installed webpack, npm start doesnt working. It gives me:
my-todo-react#0.1.0 start /home/hanna/Desktop/projects/my-todo-react
react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.19.1"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
/home/hanna/node_modules/webpack (version: 4.20.2)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if /home/hanna/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-todo-react#0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-todo-react#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/hanna/.npm/_logs/2018-10-02T10_39_06_361Z-debug.log
Create a .env file in the root directory of the project and add this line SKIP_PREFLIGHT_CHECK=true inside the file.
then try to run yarn start.
To solve this issue I had to uninstall webpack and webpack-dev-server from the node-modules folder and then install them again but with different versions.
Open cmd on the node-modules folder outside of your project folder
Uninstall webpack and webpack-dev-server:
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node-modules folder and the package-lock.json file from your project's folder.
Open the node-modules again
npm install webpack#4.19.1
npm install webpack-dev-server#3.1.9
Use this command on your project folder
npm install
It did the trick for me, hope it helps you too.
One solution I had was to go to my "Home" folder and delete the node_modules
folder and package-lock.json file.
Worked afterwards.
Since it looks like the project uses Create React App, Webpack is probably already a dependency in the package.json. So the easy way to install it is to just go to the project directory and type npm install (or yarn install) in the terminal.
If using the Webpack CLI causes errors, it's probably because there's a different version installed globally.
To uninstall it globally, type npm -g uninstall webpack.
I had similar problem today. I resolved with the following steps:
Execute npm ls webpack --> to find out that I have installed Webpack outside my folder ("like yours ... /home/hanna/node_modules/webpack).
Then cd into that location (/home/hanna/node_modules/) and execute npm install webpack#4.19.1.
That way I have the same version of Webpack like in my project folder.
After that, when I run npm start, it works fine.
Go to your project directory where you are running npm start and run the command
touch .env
If there is no pre-existing .env file in your project this will create it.
Got to .env file and add the following code (if you are on LINUX box you do this by typing nano .env otherwise just use a text editor.
SKIP_PREFLIGHT_CHECK=true
Save the file and try running npm start again.
This solution is exactly what is suggested in the error message and it worked for me
do this
first code in terminal this -->
yarn add --dev dotenv
create .env file in root directory then add below line in the .env file
SKIP_PREFLIGHT_CHECK=true
Go to /home/hanna and type npm i webpack#required_dependency. It should solve your problem.
If someone still facing this issue and uses yarn instead of npm can do (I am a mac user):
Open a terminal
Type yarn remove webpack
Come in to your project directory using your file explorer
Delete everything there
Open your code-editor
Delete hidden filers (ETC: .env or .gitignore files) if exists
In your project directory open a terminal and type npx
create-react-app . and hit enter.
And restart the app typing yarn start after download.
It worked for me. It downloaded the web pack which is needed from react-scripts.
I encountered the same issue and following worked for me:
Delete the node-modules folder and package-lock.json file
Downloaded and installed Node.js
npm install webpack#4.19.1
npm install webpack-dev-server#3.1.9
Deleted babel-eslint entry from package.json
Used this command on the project folder: npm install
Finally yarn start or npm start
I think if you have a webpack package installed globally it might cause such error. Removing it globally might solve the problem. That's what I did here and it works.
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node_modules folder and the package-lock.json file from your root directory
##thompsonmax##
Then you can now run your command to your app,
create-react-app react-app
Step 1: Create an .env file in the root directory
Step 2: add this line into your .env file: SKIP_PREFLIGHT_CHECK=true
Step 3:Again npm start
After a lot of trials, I found that the easiest solution is to install the required version of webpack in /home/hanna.
That is,
cd to /home/hanna
run npm i webpack#4.19.1
Then, the error will go away. Hope it helps.
Your problem is you installed webpack version: 4.20.2
You need to install an earlier version "webpack": "4.19.1"`
Your problem is you installed webpack version: 4.20.2
You need to install an earlier version "webpack": "4.19.1"` ..So
$npm uninstall -g webpack
and
$npm install -g webpack#4.19.1
Hope that helps
I think if you have a webpack package installed globally it might cause such error. Removing it globally might solve the problem. That's what I did here and it works.
Due to newer versions, this worked for me:
Open a terminal window (command prompt) on the node_modules folder outside of your project folder
Uninstall webpack and webpack-dev-server:
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node_modules folder and the package-lock.json file from your project's folder.
Open node_modules again
npm install webpack#4.28.3
npm install webpack-dev-server#3.1.14
Use this command in your project folder:
npm install
I couldn't find a way to uninstall the whole node module folder the only way is to delete the whole file using command line
rm -rf node_modules
npx create-react-app nameOfYourApp
find where is your nameOfYourApp and replace src folder with one from previous project
use new nameOfYourApp
If you have multiple node_modules folders with different versions of dependencies one may conflict with the other - do the following:
Follow steps 1-4 that are initially provided in project directory and commit updated changes locally~
i. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
ii. Delete node_modules in your project folder.
iii. Remove webpack from dependencies and/or devDependencies in the package.json file in your project folder.
iv. Run npm install or yarn, depending on the package manager you use.
Find the location of the node_modules folder that is not in your project folder ~ this line - (/home/hanna/node_modules/webpack)
Delete it
npm start
should work :)!
I also faced this issue. I had to install webpack#4.42.0 in the node_modules but after I installed webpack#4.42.0 there was an error displayed in the CMD:
`-- UNMET PEER DEPENDENCY webpack#4.42.0
npm ERR! peer dep missing: webpack#^5.1.0, required by terser-webpack-plugin#5.2.4
So installing webpack for node_modules didn't work. Then I used .env file to solve this.
First I typed npm add --dev dotenv in the project terminal.
Then I created the .env file and typed this code:
SKIP_PREFLIGHT_CHECK=true

Node MODULE_NOT_FOUND

I just upgraded to node version 9.0.0 and am now getting this error in the command line when trying to use npm install
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'internal/util/types'
I'm using:
OSX 10.10.5
Node version 9.0.0
NPM version 5.5.1
Extra information: I am also trying to do this with a Laravel 5.5 project. This is how I update my version of node: How do I update Node.js?
run
rm -rf /usr/local/lib/node_modules/npm
and then re-install Node.js will work in most cases
Leaving this here for anyone using the n nodejs version manager:
$ n 6.12.0 # Go back to a stable release
$ npm install -g npm#latest # Update npm to latest
$ n lts # Get 8.9.1
$ npm install #Should work now.
The MODULE_NOT_FOUND error seems to happen when changing between node versions and some files are possibly still being cached. I am not sure exactly but the above sequence of commands work for me.
When I first got this, I solved just running "npm install" again to make sure everything was installed.
I got similar error also on Windows 8 after I have just upgraded node js. First: how I ran into the issue then the solution that worked for me.
How I ran to the issue:
When I did npm --version and node --version I discovered that I wass running npm v3.x and node 5.x. So I went to nodejs.org site from where I downloaded node-v8.11.3-x64.msi. After installing the msi package I confirmed that my nodejs version was now v8.11.3 via node --version command.
Then, when I ran "npm install http-server" (w/o the quotes) that's when I got the issue:
npm ERR!
node v8.11.3
npm ERR! npm v3.5.3
npm ERR! code MODULE_NOT_FOUND
My resolution:
I did some research including on the internet and found out that the npm version pointed to in my path was the one in my roaming profile C:\Users[myname.hostname]\AppData\Roaming\npm. In other words, the npm being used is not the one in the updated package I have just installed which is located in C:\Program Files\nodejs.
The resolution was to delete npm and npm-cache in the roaming folder. Note, I used cygwin as I was not able to delete these folders via Windows cmd prompt. With cygwin, I navigated to
cd "C:\Users[myname.hostname]\AppData\Roaming"
Then I removed the aforementioned folders like so
rm -rf npm-cache
rm -rf npm
After that, I opened a new Windows cmd prompt and was able to now successfully install http-server like so:
npm install http-server
Hope this works for you.
For me it was package installation issue, so I just write,
npm i or npm install in the root of the application.
to open the terminal in the root of the application, if you're using VS-code right click on the package.json and click on Open in integrated terminal.
I founded this problem too, so I found that I have imported wrong module instead of express module I had imported router module after I had replaced this two my code work as well
If all the above solutions doesn’t work check for any blank spaces in your folder/file where you copied the path
Make sure you are inside the project folder.
Rename the folder "node_modules" to any other name (for example: node_modules_old).
Run command: "npm i" (the command will build new the folder node_modules).
Try running your program again.
If the problem is resolved and your program is running correct, delete the old folder node_modules.
If you are using libraries make sure to install everything with npm or yarn before starting. And in cases of you files if you are going to use them make sure to do the export.module thing everytime.
If you are working with Local modules then don't have node_modules. All things go well in a easy way.
But if you want to work with both local and node_modules then use
.mjs (extension) - For modules
.cjs (extension) - For common scripts which you want to run with node
in which you can use require statements like
var http = require('http');
var fs = require('fs');
but if using .js extension then use
import http from "http"
import fs from "fs"
And also your package.json for type
Haa well, I have spent two days on this and have done everything I can to fix this issue even tried resetting the system but none of them reloved the issue.
And accidentally found out what was causing this issue, it is because of & in my parent folder name. File hierarchy R&D>remix>blog, When I was trying to run the blog server it was throwing module not found, require stack error.
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
Solution: I have changed the parent folder name to RnD and it fixed the issue. If the file name contains any special characters(even parent folders) try updating it. In my case, it is &
The MODULE_NOT_FOUND error happened to me and even running npm install the error persisted.
Try to do this
For me, what worked was deleting the node_modules folder
rm -r -f node_modules/
After that, run the command to install the package.json dependencies
npm install
What happened to me was that when I ran npm install for the first time I had a very low internet connection and therefore I believe that the packages from package.json were not downloaded correctly and due to that the MODULE_NOT_FOUND error occurred. The funny thing is that just running the npm install command has no effect because it understands that the package is already there but it isn't. Similar as a corrupted data. In my case the npm update was without effect too.
If when you are using React And getting this error message. You can use this ,
NPM
npm install #reduxjs/toolkit
Yarn
yarn add #reduxjs/toolkit

npm package install issues

I'm having a problem with npm.
When I install packages they will go to the node_modules folder, but instead of the package assets being in one folder it puts them outside of that folder.
In the express folder, all of the folders in that are supposed to be inside, but instead, they are outside of it. This also happens with other packages I try to install. I have tried creating a test project, but the same thing happened,
And I also tried uninstalling node and npm, and it is still happening.
You sure it's not dependencies?
NPM will install additional packages if you need them, and place them in root of the node_modules folder so that other modules later can use the same if they need them.
After running (edit: npm init first to get package.json in the root of the project) npm install express --save on empty project, I end up with
PS. Apologies if I misused terms, I'm still quiet new to node and npm
I found out what happened it was because of node v5.1.1 that the package folders were saving outside of the express folder once I went back to node v4.2.3 it made a node_modules folder inside the express folder.
Thanks again for everyones help

Resources