npm install is missing modules
Asked Answered
H

10

27

Before I can run gulp in my project I need to run npm install. This works except on my computer, because I get the following error:

Error: Cannot find module 'socket.io'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    ...

I can fix this with

$> npm install socket.io

Now when I do the install command again I get

Error: Cannot find module 'di'
    ...

When I install di and run the install command again I get:

Error: Cannot find module 'log4js'

I think that this might continue for a very long time. Any suggestions what is going on here and how to fix this ?

Hysteria answered 9/7, 2014 at 11:38 Comment(1)
I have inherited a project where the original author apparently installed all dependencies globally or without -S flag. No answer here really answers this question. Is there not a way to automatically install all missing dependencies discovered as imported within the project files on build time by static analysis?Lunetta
A
29

I've faced the same problem when bootstrapping a MEAN application and add each missing dependencie with npm install packageName --save was not an option so I came across to npm-install-missing whom has saved my life :)

Installation

npm install -g npm-install-missing

Usage

npm-install-missing
Appose answered 23/9, 2015 at 22:30 Comment(5)
When I try this It tells me that I have no missing modules, although when I run npm list It is loaded with missing and unmet dependencies.Cadmar
For me this also says it is finished but does nothing sadly!Revisionism
This just goes through package.json in each dependency. I need to install dependencies, which are used in project, but somehow forgotten to install.Lunetta
Getting UnauthorizedAccess. This is why I hate these pesky platforms with 9000 dependencies, in which 75% are outdated. Just stick to C++.Kingery
Sadly an outdated answer: Error: The programmatic API was removed in npm v8.0.0Ance
F
18

Running npm install will install all dependencies that are specified in the package.json. Seems like you have quite a few dependencies that are not defined that way. Use npm install packageName --save and npm will add the package to your package.json.

Foppish answered 9/7, 2014 at 11:45 Comment(4)
I have about 50 packages in my package.json file. As far as I know, the dependencies of these packages are handled by the package.json of these packages!Hysteria
@JeanlucaScaljeri Yes they are. Do you use the latest version of Node & npm?Foppish
This answer is not a solution. some missing module are dependencies of other module. npm: 2.15.1 have the same issue.Fortification
Since 2017 --save is not needed.Bowyer
D
7

I am using the same version of npm/node. Sometimes, it is like npm is "lost". What I suggest is :

  • rm of your node modules (at least the one that is concerned)
  • npm cache clean
  • run "npm install" several times, until all dependencies are resolved and no message are displayed
Dyslexia answered 5/9, 2014 at 15:23 Comment(1)
When you use npm cache clean it now says use npm cache verify instead, and both commands say you have to use the --force flag.Prototherian
C
3

It seems that gulp need 'karma' dependencies (socket.io ,di ,log4js...) so you will have to run :

npm install karma

so just runing this command solved the problem, and all should be good, the same thing happens with grunt as well for some reasons.

Curbstone answered 12/5, 2015 at 22:10 Comment(0)
H
0

This worked for me. By commenting 3 lines in C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js.

Refer [https://flaviocopes.com/cb-apply-not-a-function/]

// fs.stat = statFix(fs.stat) # Line: 61
// fs.fstat = statFix(fs.fstat) # Line: 62
// fs.lstat = statFix(fs.lstat) # Line: 63
Hudis answered 30/9, 2020 at 14:14 Comment(0)
S
0

Beside other answers, if you are using Angular and cannot make new angular project and hangs, you can get into the folder and open terminal and write:

npm -i

Maybe useful for other things too!!

Sapotaceous answered 13/9, 2021 at 13:27 Comment(1)
I think it wouldn't need the dash(-) before i, !!Sapotaceous
C
0

I think the npm module madge would help you find the missing dependencies. It goes through your actual code and makes a list of all the dependencies found within. You could then do an npm i for each of the modules found.

Chimaera answered 1/12, 2021 at 18:2 Comment(0)
L
0

Upgrade your npm version Install nvm which is easier to switch node js versions For me node 12.18.3 worked Just do: nvm use 12.18.3 to switch version

run npm install again and node_modules will appear

Langley answered 19/2, 2023 at 18:42 Comment(0)
P
-1

If the npm-install-missing does not work for you, knowing the name of the Packages that are missing will help you out here. All I had to do was first open my package.json file inside VSCode, then paste or type the names of the missing modules into it (under dependencies) according to the way other package names were written there. Then I ran npm install after that. This method is helpful when you are working on a file but somehow you did not get the package.json file or some of the modules are not listed therein.

Remember to stop and restart a running server after you do npm install for your new dependencies to reflect on your work.

Piscator answered 5/1, 2022 at 5:44 Comment(0)
E
-3

To resolve missing npm modules run:

sudo npm install -g npm-install-missing
Enterprising answered 25/5, 2020 at 11:49 Comment(2)
This answer was already provided in 2015. If you agree that using the npm-install-missing package answers the original poster's question, then give the answer a thumbs up. If you want to say something to clarify the answer, leave a comment under the answer, but don't create a new one.Horal
It is 8 years old one, does not work in latest nodeGambrel

© 2022 - 2024 — McMap. All rights reserved.