Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin' - node.js

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

Related

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

I just removed node_modules, how do I reinstall them all?

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.

angular cli not working on windows 10

I have just reinstall node.js, npm and angular-cli but this last one does not work on my PC running on Windows 10. The version of node.js is 8.1.2, the version of npm is 5.0.3. I installed angular-cli with the command line npm install -g #angular/cli. Now when I try any command line beginning with ng I have the error:
module.js:487
throw err;
^
Error: Cannot find module '#ngtools/json-schema'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Raphaël\AppData\Roaming\npm\node_modules\#angular\cli\models\config\config.js:6:23)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
Any idea what is wrong?
Shot in the dark, but I heard of -g installs interfering with local angular cli. However, this appears to just be a missing module from the download, maybe just a package lost. Try to uninstall and re-install again
I'm also on Windows 10. Node 8.1.4 and npm 5.2.0
What worked for me was following the steps from an issue thread I found on github: https://github.com/angular/angular-cli/issues/4425
. The link describes the following steps:
Uninstall angular cli
npm uninstall #angular/cli -g
Install rxJS
npm install rxjs -g
Cleared cache
npm cache clean
Manually deleted content in
%AppData%\npm\node_modules
Installed angular cli npm install
#angular/cli -g
Try downgrading node to v7 and npm to v4 then run:
rm -rf node_modules dist
npm cache clear --force
npm install
There are also some threads mentioning the removal of package.lock which is a new part of npm#5. Furhtermore it is worth checking you typescript version ensuring it is > 2.2.0.

Nodejs and npm error. modules missing

module.js:340
throw err;
^
Error: Cannot find module 'vinyl'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/morpheyesh/debugall/web-starter-kit/node_modules/gulp/node_modules/gulp-util/lib/File.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I have major issues with node.js. I try to run any nodejs application or gulp, i get this error, I try to install every module , I keep getting the same error and it requires a new module. Is there anyway where I can install all the modules?
Plus, I have install nodejs through npm? how to install system wide? Gulp is been installed system wide(global). What is causing this error?
nodejs -v gives v0.10.30
`npm -v gives 1.4.21
gulp 3.8.7
I am working with the google web starter kit. I installed nodejs using apt-get, then install sass, then installed gulp, then npm. Is there a way where I can remove all these and install all of it system wide?
Try updating your global gulp installation:
sudo npm install --global gulp#latest
It sounds like everything is (was?) FUBAR for a while there. If you have not yet solved these problems, here's what I would recommend.
First, the official (Debian/Ubuntu) packages are a bit behind latest node. I would recommend uninstalling the packages nodejs and nodejs-legacy and following the instructions here to get the latest versions (packaged and published by nodesource): https://github.com/nodesource/distributions#usage-instructions
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
Now you will have a recent node (0.10.35) but an out-of-date npm. Upgrade your npm:
npm install -g npm#latest
Things should now work for you; you should be able to run npm install in your project directory and all dependencies will be installed correctly.
One thing to be wary of is that you should never run npm update or npm update -g. This does not update the current (or all global) packages, as one might think.
Try this for install all plugins required by gulp :
npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev
Source : http://travismaynard.com/writing/getting-started-with-gulp
For me uninstalling gulp and then reinstalling it worked fine. This is with node v5.0.0
sudo npm uninstall -g gulp
npm install -g gulp

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