I just removed node_modules, how do I reinstall them all? - node.js

Initially I was just trying to run a demo app to practice mongoose. The app, cats.js, would not run with node because I would get this error:
module.js:540
throw err;
^
Error: Cannot find module './timestamp'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/taylorlassiter/Desktop/visual_studio/yelp_camp/node_modules/bson/lib/bson/bson.js:6:15)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
Unfortunately, the ./timestamp module appeared in all the places listed in the error.
I read How do I resolve "Cannot find module" error using Node.js? to try to fix it and ended up running "rm -rf node_modules" which removed all node_modules. When I tried to reinstall with "npm install", I get these errors:
npm WARN bootstrap#4.0.0 requires a peer of jquery#1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap#4.0.0 requires a peer of popper.js#^1.12.9 but none is installed. You must install peer dependencies yourself.
I haven't seen any answers regarding these two errors.
My first priority is getting npm reinstalled. My second priority would be to figure out the original error I was receiving when trying to run cats.js, but I can create a new question for that.

What is happening is that you have a module that depends on another as a peer dependency. Peer dependencies were created to solve a problem with plugins. Have a look at these posts for more information; npm peer dependecies and understanding the npm dependecy model
If you have ran npm install and got this error it seems that you don't have jquery#1.9.1 and popper.js#^1.12.9 installed and saved to you package.json
To get rid of this you should manually install them first, then run npm install again. Try this;
rm -r node_modules
npm install jquery#1.9.1 --save
npm install popper.js#^1.12.9 --save
npm install

During previous installation of your
node_modules, if the save flag was enabled then all those modules must be having an entry in your package.json's dependencies object.
In that case just do npm i short for npm installand every module that you earlier had will get reinstalled.
If there isn't anything in your package.json's dependencies object, then you need to install each of your module again by specifying the module name and this time don't forget to mention the --save flag.
Just start doing npm i dep-1 dep-2 ... --save.
If you find writing --save a little exhausting then just do this once in your repository.
npm config set save=true
This will enable save flag for each dependency you will install here onwards.

Related

laravel vue ui npm run dev [duplicate]

I have webpack-cli installed on my laravel project. I don't know why first of all we need it to run my vue app but this is causing an error:
When I run npm run dev or npm run hot
[webpack-cli] Error: Cannot find module 'webpack/lib/rules/DescriptionDataMatcherRulePlugin'
Require stack:
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\vue-loader\lib\plugin-webpack5.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\vue-loader\lib\plugin.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\vue-loader\lib\index.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\laravel-mix\src\components\Vue.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\laravel-mix\src\components\ComponentRegistrar.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\laravel-mix\src\Mix.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\laravel-mix\setup\webpack.config.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\webpack-cli\lib\bootstrap.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\webpack-cli\bin\cli.js
- C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\webpack\bin\webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (C:\Users\Viruss\Desktop\test-meme-library\meme-library\node_modules\vue-loader\lib\plugin-webpack5.js:6:42)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\vue-loader\\lib\\plugin-webpack5.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\vue-loader\\lib\\plugin.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\vue-loader\\lib\\index.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\laravel-mix\\src\\components\\Vue.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\laravel-mix\\src\\components\\ComponentRegistrar.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\laravel-mix\\src\\Mix.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\laravel-mix\\setup\\webpack.config.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\webpack-cli\\lib\\bootstrap.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\webpack-cli\\bin\\cli.js',
'C:\\Users\\Viruss\\Desktop\\test-meme-library\\meme-library\\node_modules\\webpack\\bin\\webpack.js'
]
}
Vue is installed also vue-loader, can't understand why it can't find those files. Also, I looked at the node_modules everything is in there ...
You need to update your vue-loader
npm update vue-loader
And if it is not installed, install it
npm i vue-loader
Laravel added the 15.9.7 version of Vue-loader by default. I have to manually update the vue-loader:^15.9.8 in the package JSON to solve the error.
Then do yarn and yarn dev or npm install and npm run dev
I had this error in my project. After searching for it, I discovered that I have to upgrade the Vue loader. And if not installed, go ahead and install it from here. So I add this line to my terminal in my project.
npm install -D vue-loader vue-template-compiler
running
npm update vue-loader
should do the work just fine if the vue-loader package is already installed.
Some of those updates are major releases. Running npm update won’t update the version of those. Major releases are never updated in this way because they (by definition) introduce breaking changes, and npm want to save you trouble.
Some times npm packages not gets installed properly, i used following method to resolve this problem:
**
Delete node modules folder from your project.
Execute following commands
npm install -g npm-check-updates
ncu -u
npm install/update.**

create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executed

when I try to create a react project with both npm and yarn, it shows me the following error:
I tried to reinstall node and make sure it was up to date, as well as create-react-app by running npm install -g create-react-app#latest. I also removed the npm and npm-cache folders and the environment variable, but nothing works for me and I keep getting the same error.
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'react-scripts/scripts/init.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at [eval]:2:20
at Script.runInThisContext (vm.js:122:20)
at Object.runInThisContext (vm.js:329:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at evalScript (internal/bootstrap/node.js:589:27)
Aborting installation.
node has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting test/ from C:\Users\Esper\projects
Done.
I think the problem arose from restoring my windows 10 to a previous state due to operating system problems, because before restoring it, when I run create-react-app it worked correctly.
create-react-app --version
3.1.1
node -v
v10.16.3
npm -v
6.9.0
SO
Windows 10 Education
Install a package.json with npm init (press enter till is installed)
After that install react-scripts with npm i react-scripts,
Then you can install react with npx create-react-app your-app.
Change the directory to "your-app"
Run again npm i react-scripts and it should work.
Hope I did not missed a step, let me know if works :)
Just run this code on git bash:
npm install
npm install react-scripts
npx create-react-app your-app-name
Maybe it will help somebody else.
This error can happen after you use create-react-app in case you have some invalid character in your path.
Remove charecteres like & from your path.
For example, change from this:
C:\Users\...\Documents\Section 3 Components & Start\my-app
To this:
C:\Users\...\Documents\Section 3 Components Start\my-app

npm cannot install 'node-sass'

I'm trying to run a project with npm start and then get the following error in a bunch of different components:
Module build failed: Error: Cannot find module 'node-sass'
Alright, I'm thinking and I run 'npm install node-sass', which then leaves me with the following error:
Error: EINVAL: invalid argument, open '/usr/app/client/node_modules/node-sass/package.json'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.Module._extensions..json (module.js:670:20)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/app/client/node_modules/node-sass/lib/extensions.js:7:9)
at Module._compile (module.js:653:30)
I don't know what it means or what I can do to resolve it, I tried commands like npm rebuild, npm uninstall and then install again, deleted the node_modules folder but that doesn't seem to do the trick.
I think this would work.
The package.json I have was written like the following.
"devDependencies": {
...
"node-sass": "^4.5.0",
...
}
npm install node-sass
npm install node-sass#latest
npm rebuild node-sass --force
npm install node-sass --force
Ok, so the solution to my specific problem was:
npm install node-sass --force
and then I had to do
npm rebuild node-sass --force
And then I got it to compile
Try running :
npm install node-sass --force
It would work.
npm install --unsafe-perm node-sass
in Linux:
sudo npm install --unsafe-perm node-sass
None of those options worked for me. I was trying to install node-sass version 4.14.1 and this seemed to work:
git clone --recursive https://github.com/sass/node-sass.git
cd node-sass
npm install
node scripts/build -f
cd ..
npm install node-sass --sass-binary-path=C:\Users<you-path>\node-sass\vendor\win32-x64-93\binding.node
That seemed to work for me. But then after all that effort, v.4.14.1 was incompatible with another package so I was ready to flip a table by that point < insert-table-flipping-meme >.

Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'

Got this Error after running webpack. Webpack is installed globally and I'm running Node
PS D:\Projects\ng2-admin-master> ng serve
Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Projects\ng2-admin-master\node_modules\html-webpack-plugin\lib\compiler.js:11:26)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Projects\ng2-admin-master\node_modules\html-webpack-plugin\index.js:7:21)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
PS D:\Projects\ng2-admin-master>
Update (Apr 2018)
Webpack 4 onwards you are required to install webpack-cli. You may also want to install webpack-dev-middleware if you need to use the options marked with a key on this page.
In this case the command to install is:
npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware
As mentioned above, webpack-dev-middleware should be optionally added based on your requirements.
Older answer
Node requires you to install webpack to your project.
You have 2 options to solve the above:
Remove global webpack and install it locally
npm uninstall -g webpack
npm install --save-dev html-webpack-plugin webpack webpack-dev-server
You can link the global webpack pkg to your project's node modules. The downside of this is that your project will be forced to use most updated webpack. This will create a problem only when some updates are not backwards compatible.
npm i webpack -g; npm link webpack --save-dev
You can omit the html-webpack-plugin depending on your requirement.
You can find more info on this github issue page.
I faced a similar issue when updating my Angular app using ncu. Finally solved it by:
remove the node_modules directory
remove package-lock.json
reinstall the packages.
You can run this in PowerShell (make sure you are in the correct working directory):
rm node_modules -r -force
rm package-lock.json
npm cache verify
npm install
Context:
I had this problem with a React application.
I tried to uninstall webpack globally and locally, also deleted the local folder node_modules, reinstalled all local npm modules (with npm install), etc.
Nothing worked, until doing this...
Solution:
Remove package-lock.json & node_modules.
Don't remove the other files (like: package.json, index.js...)
Install all package (npm extracts information for the installation from package.json) with npm install === npm i.
Now, run your code and voila! 🎉
I tried for hours almost every thing suggested on different threads on Stack overflow but nothing worked. Eventually (with a lot of luck) I tried this and it worked:
deleted node_modules library (not sure if required)
npm install -g #angular/cli
npm install #angular/cli
npm install
This happened to me after I configed 'react-bootstrap' in my next js app.
try adding this fixed my problem:
yarn add webpack#webpack-4
or if using npm:
npm i webpack#webpack-4
Below worked for me:-
Removed node_modules
Deleted package-lock.json
Run npm install
Check webpack.config.js and make sure all dependencies are installed.
I was having the same problem too. It was resolved by installing html-webpack-plugin dependency. It was defined in my webpack.config.js but not installed.
Remove the package-lock.json and try npm install it will resolve the issue.
This is work for me:
1. npm uninstall -g webpack
2. rm node_modules -r -force
3. rm package-lock.json
4. npm install
You have to check webpack modules already install in the node_modules folder or on your machine? if not install it
For me I fixed this error with:
yarn add --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware
It happened when I installed using yarn while the project used npm. I removed the node_modules folder then tried again with npm i
rm -rf node_module
npm install
The reason for this is that the project used specific packages versions which are compatible together but using yarn installed the newest versions which may not fully compatible with the current project.
Check which lock file the project uses then use the corresponding package manager.
This will fix your problem:
npm remove webpack -g
npm i webpack --save-dev

node npm install -g cannot find module config-chain

I configured the node plugins on jenkins to install grunt and bower globally.
When i use it on a project npm install is executed:
npm install -g bower#~1.2.8 grunt-cli#~0.1.11
Unfortunally it breaks immediately returning the following error:
module.js:333
throw err;
^
Error: Cannot find module 'config-chain'
at Function.Module._resolveFilename (module.js:331:15)
at Function.Module._load (module.js:273:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/Users/Shared/Jenkins/Home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node_0.11.10/lib/node_modules/npm/node_modules/npmconf/npmconf.js:2:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Module.require (module.js:357:17)
I dont think config-chain is an extra plugin necessary to be installed for it to be there.
Any ideas how to fix this?
Edit.: Fixed it thanks to the accepted answer:
npm auto-install isnt supported for mac at this time. I had to download the package manually.
config-chain is npm dependency, so chances are that your npm installation is broken.
Try to reinstall it, or use one of npm forks if npm itself isn't installable on your system for some reason.
Follow this suggest, i resolve it.
"Who ever faces this problem, please do a clean install of ionic"
npm install -g ionic
If it got installed and you're still facing issues, easily install each missing module you face, globally example
npm install -g config-chain
This will re-install all missing modules, as this might have happened when you upgraded your node
https://forum.ionicframework.com/t/cannot-find-module-config-chain/37130/7"
I encountered a different problem.
It appears as though the Jenkins NodeJS plugin was incorrectly downloading and unpacking packages from the Node.js website. When I went to go look at the unzipped folder and did an npm list, there were several packages missing.
I fixed this by telling Jenkins to download a zip file directly and unpack it.
It was the same issue.
I had moved NPM prefix to 'C:\ProgramData\npm\' (you can see your prefix in 'npm config list' command).
After that I should install global packages only under the administrator credentials.

Resources