I have an Angular CLI project which I just upgraded to Angular 6. Now when I try to build my app, I get the following errors:
ERROR in ./node_modules/postcss/lib/input.js
Module not found: Error: Can't resolve 'path' in '/Users/jattardi/code/myproject/node_modules/postcss/lib'
ERROR in ./node_modules/postcss/lib/map-generator.js
Module not found: Error: Can't resolve 'path' in '/Users/jattardi/code/myproject/node_modules/postcss/lib'
ERROR in ./node_modules/postcss/lib/previous-map.js
Module not found: Error: Can't resolve 'path' in '/Users/jattardi/code/myproject/node_modules/postcss/lib'
ERROR in ./node_modules/htmlparser2/lib/WritableStream.js
Module not found: Error: Can't resolve 'stream' in '/Users/jattardi/code/myproject/node_modules/htmlparser2/lib'
I'm confused. First off, I am not even using postcss
or htmlparser2
directly in my project. So they must be dependencies of something else.
But aren't path
and stream
built in Node modules? How could it not be able to resolve them?
To solve the "Module not found: Can't resolve" error in React, make sure to install the package from the error message if it's a third-party package, e.g. npm i somePackage . If you got the error when importing local files, correct your import path.
If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies. The module you're trying to import is in a different directory. The module you're trying to import has a different casing.
To fix the Cannot find module error, simply install the missing modules using npm . This will install the project's dependencies into your project so that you can use them. Sometimes, this might still not resolve it for you. In this case, you'll want to just delete your node_modules folder and lock file ( package-lock.
npm install path
npm install stream
did the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With