Node MODULE_NOT_FOUND - node.js

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

Related

Why is it that npm install doesn't work on my device and I am unable to view the version details even though I've reinstalled?

I'm completely new to using Node and am honestly very confused about how this all works. I have installed node and NPM but every time I try to check the version to see if it's installed, it tells me "command not found". I've been at this for almost 2 hours just deleting all the npm/node files and reinstalling but nothing seems to give. Can someone please explain if there is anything I can do to fix this issue?
-bash: npm: command not found
If I go inside the NPM file through the terminal, it shows me this when I try to run npm install or npm start.
> npm start
npm should be run outside of the Node.js REPL, in your normal shell.
(Press Ctrl+D to exit.)
Add npm to your path (environment variable on windows not sur on linux) if you are using a portable version, if you are using an installed version of node, it should add npm to your path automatically on windows, not sure on linux, npm start will run the start script from your project package.json file. try going into your npm executable folder (generally in node installation folder), n do a ./npm i -g npm

Why is "npm install" looking for a file that doesn't exist (package.json) on a fresh NodeJS installation?

Hello, World!
I am having trouble getting NPM working.
First, I installed node.js from https://nodejs.org/en/download/ (the 64-bit .msi, on Windows 10, Version 10.0.18362 Build 18362). Node -v is 12.16.3.
Using Powershell, I navigated to the nodejs directory created in the install. Then I attempted npm install, which ultimately drew a series of errors beginning with "ENOENT: no such file or directory, open '...\nodejs\package.json' ".
The nodejs directory contains a file called "package-lock.json", but no "package.json".
Renaming the "-lock" file did not fix the error.
I've read on this site that Node came with NPM pre-installed. I can run npm -v without a problem ("6.14.4" returned) but trying npm start gives me the same error as npm install (cannot find package.json).
I have uninstalled Node & reinstalled twice, same problem.
Thoughts?
You should create a package.json file for every project using npm libraries, whether or not you are going to publish your code anywhere.
The easiest way is to run npm init and answer the questions, then npm will create the package.json file.
(Or take a look at the docs for other ways to run init, like npm init -y to just generate a plain package.json that you can manually edit.)
BTW, package-lock.json is a different kind of file that's generated to say which versions of each transitive dependency were installed. It doesn't have the same format as package.json; don't mix them.

Why do Node modules go into .staging folder?

I have an Electron app that I'm trying to install node modules for. When I run npm install, it creates the node_modules folder but all the modules go into a subfolder called .staging. Each module also has -xxxxx appended to it, where the x's are some random alphanumerics.
Other Electron apps I've created have never done this. All the node modules sit in the root of node_modules and don't have -xxxxx appended.
Any idea why this is happening?
I was also facing the same issue, I tried the steps below:
Delete package-lock.json
Delete Node Modules folder
Try installing it using below command (should be in open network)
npm install
Note: - ".staging" means, those dependencies are getting downloaded so for the temporary basis it keeps all those dependencies under ".staging" folder. Once all gets downloaded properly then it will showcase them under node_modules only.
I hope this will work.
This only happens temporarily until the modules are downloaded and installed. Node seems to do this so it can place together common submodules from all the modules you are installing so it can better structure the node modules folder(mainly for windows users).
If this is happening after an npm install finishes it is likely that there is something wrong with your node installation or something in the install failed.
If you're automatically installing node_modules using CI/CD you should check out npm ci. Also check out this Stackoverflow question.
npm ci
The documentation points out the differences between npm install and npm ci.
The project must have an existing package-lock.json or npm-shrinkwrap.json
If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
If a node_modules is already present, it will be automatically removed before npm ci begins its install. This is nice, because it prevents having to do something like rm -rf node_modules.
It will never write to package.json or any of the package-locks: installs are essentially frozen.
.staging is a temporary npm folder, where the modules are temporarily saved while they are being downloaded, if the package.json downloads are still not completed, the created folder remains, until the installation is complete.
The problem may be lack of space on your hard drive.
I was having 2 versions of node installed on my system.
nodejs v4.2 and node v8.6
I thought this could be conflicting, so I deleted nodejs v4.2 with following commands.
sudo apt-get remove nodejs
and linked the path with
sudo ln -s /usr/bin/node /usr/bin/nodejs
Again I ran npm install and it got fixed
Delete package.lock.json
Delete node_modules
run npm update
This worked for me
I moved the project from C drive to other drive and ran the following commands
take a backup of older node modules if you are running this and existing project
npm cache clean --force
npm update
I faced similar issue and tried the above answers but it did'nt worked for me;
I followed below steps to resolve this issue-
1.npm audit
By running npm audit I got list of pending packages to install-
2.npm i packagename
After installing one or two package one by one from list, I used
3.npm install
At this time the installation went smooth without any lag or hangup. Hope this help who is facing similar issue :).
Sometimes the cache is corrupt and also unremovable.
This fixed the issue I was experiencing.
If you are using nvm
Get the current node version node --version
nvm uninstall (that version)
nvm install (that version)
nvm use
npm install
If you have a windows machine where you do not posses Admin rights to it.
Try deleting node_modules and install using 'npm install' from command line as
'ADMINISTRATOR'
It works!
Anyways, it comes down to an open network thing ;)

libsass bindings not found when running gulp dist

I'm trying to use a gulp project on my Linux machine. The readme for the project tells me to first run sudo npm install -g gulp bower, then in the project directory run sudo npm install and then bower install. Everything up to this point works just fine for me. However, after that I try to run gulp dist and get this error:
Error: `libsass` bindings not found in /[PROJECT DIRECTORY]/trunk/node_modules/gulp-sass/node_modules/node-sass/vendor/linux-x64-14/binding.node. Try reinstalling `node-sass`?
Googling that error produced this: libsass bindings not found when using node-sass in nodejs, which I tried, but that didn't fix anything. When I looked through that directory that gulp said it couldn't find the difference was the linux-x64-14, mine said linux-x64-11, so I'm assuming I have the wrong version? Just for fun I decided to try changing the name of that folder to what it wanted, and I got a different error:
Error: Module did not self-register.
The really strange thing about all this is that when I tried getting this project working on my Windows machine I didn't have any of these issues, it just worked. I have no idea what I'm doing wrong, any ideas?
I've solved this by updating GCC from 4.4.x to 4.7.x.
Because GCC 4.4.x cannot compile node-sass of current version.
It worked for me using below commands. Try it
npm rebuild node-sass
rm -rf node_modules
npm i
This error usually shows up for us when we update our node or io.js version.
I would recommend deleting your node_modules folder and running npm install again.
If that doesn't work it is probably worth deleting your npm cache. There are a number of ways to do it including just a simple npm cache clean
I would also recommend deleting your ~/.npm folder as well just to be sure.
If this doesn't work let me know and we can start debugging your actual Node version and your package.json

dyld: lazy symbol binding failed: Symbol not found: _node_module_register

I have tried reinstalling and rebuilding npm, but the problem still persists.
Initially, the problem is with the module mongodb: I don't have that package, so I installed mongodb using this command npm install mongodb.
It shows me the following error:
dyld: Symbol not found: _node_module_register
Try deleting your node_modules folder and running npm install again.
rm -rf node_modules/
npm install
That should fix it.
Basically this error means - some binary packages was built under different node.js versions and not compatible to each other.
Via NVM make sure you are using proper version of node.js, run node -v;
After installing and switching to proper node.js version via nvm run npm update;
After all packages are updated (or downgraded) to compatible versions, run npm rebuild;
Note: npm rebuild might throw errors - just run npm rebuild again and again until it runs successfully.
Note: some commands may ask for root (sudo) permissions, - it depends from how you have installed packages, npm and node itself previously. nvm - never needs to be run as root (sudo).
If you just updated node and are running scripts via WebStorm, make sure you edit your Run/Debug Configurations and update the path to the Node Interpreter. I was using the node in
/usr/local/bin/node
, but after installing Node 4 using nvm, I need to use
/path/to/.nvm/v4.2.2/bin/node
This is what worked for me:
rm -rf node_modules/
sudo npm install
Make sure your nvm is pointing to the correct nodejs version. For me I used different (higher) while installing the npm modules. So just ran **nvm use** v14.7.0

Resources