I am new to Node.js and hitting this problem on my DigitalOcean VPS, where my web app (Ghost) complains it can't find specific modules even after I install it:
root#3fen:/var/www/ghost# sudo npm install -g ghost-gql
ghost-gql#0.0.2 /usr/local/lib/node_modules/ghost-gql
└── lodash#3.10.1
root#3fen:/var/www/ghost# node index.js
ERROR: Ghost is unable to start due to missing dependencies:
Cannot find module 'ghost-gql'
Cannot find module 'jsonpath'
Please run `npm install --production` and try starting Ghost again.
Help and documentation can be found at http://support.ghost.org.
I confirmed that both entries exist in package.json's dependencies block, and I also tried npm install --production, it executes silently and still get the same error.
Please point me if I am missing anything in the above steps. Thank you!
it looks like global npm path is not set in the environment variable NODE_PATH.
which needs to be the path as in npm config get prefix concatenated with node_modules
In your case
export NODE_PATH=/usr/local/node_modules
Related
I deleted the node modules and package.json.lock file in my client side MERN Stack project folder and tried reinstalling the node modules by typing "npm install" command in the terminal. but it's showing me an error. 1. I have tried clearing cache using "npm cache clean --force".
2. I have tried reinstalling npm using "npm install -g npm".
3. I have tried updating the npm using "npm install -g npm#latest".
But nothing works. Please help me resolve this issue. below are my package.json file and the error in my terminal while installing node modules.
i was expecting that node modules will be reinstalled with all the dependencies mentioned in my package.json file.
NPM changed the way of resolving peer dependencies in v7, but this new way does not allow conflicting dependencies in the dependency tree. The simplest way to solve this would be to use the --legacy-peer-deps option to use the old way of resolving dependencies.
The hard(but better) way to solve it would be to spend some time to update the dependencies in a way that there is no conflicting dependency.
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
thanks your time advance.
first, I publish npm package success.(verified that already in the npmjs.com profile, the package name I can call 'firstnpmpublish'(uniqueness))
second, write require('firstnpmpublish') in my test.js file and type npm install firstnpmpublish
third , type node test.js in the terminal on my mac.
but it print:
throw err;
^
Error: Cannot find module 'firstnpmpublish'
I have tried 'npm install firstnpmpublish' and 'npm install firstnpmpublish -g' and also 'npm install' as I create package.json which dependencise include firstnpmpublish. but it still doesn't work.
however, instead of require('firstnpmpublish') and using require('express'),it work smoothly.
where i was wrong? thanks
Your package.json file doesn't specify the path to your main file, so the require can't be resolved. Add the following to your package.json and then republish:
"main": "Print.js"
I'd recommend renaming that file to index.js though, to better fit with the Node conventions.
I had a very similar issue. Removing the entire node_modules folder and re-installing worked for me:
rm -rf node_modules
npm install
I have recently install nvm, node and npm. I cant seem to get the $npm list to list the modules in the node_modules folder. Other npm commands work. npm install -g installs in the correct folder which I can see by cd'ing to it. I cant figure out why one npm command works but the next doesnt. npm config shows cwd as a different folder. Do I have to change that? If so, how do i do that? Thank you.
https://gist.github.com/kaona/0d5ba467cff814dbb1691a083baa1dee
I also tried this but didnt work. I know its something simple im missing. Still new to this. Thanks.
Have you included the modules in your package.json file? The npm list command won't show a module if its not in the package.json, even if its installed in the node_modules directory.
The tree shown is the logical dependency tree, based on package dependencies, not the physical layout of your node_modules folder.
https://docs.npmjs.com/cli/ls
When you install a module into your app, use the --save or --save-dev options to update your package.json. This allows you to install all the dependencies of your application by running npm install. It will also mean that your modules show up when you use the npm list command.
https://docs.npmjs.com/cli/install - For more details
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 ?
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
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.
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
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.
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
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!!
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.
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.
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
To resolve missing npm modules run:
sudo npm install -g npm-install-missing