ansi-html-community icon indicating copy to clipboard operation
ansi-html-community copied to clipboard

Can't resolve 'ansi-html' in '.../node_modules/webpack-dev-server/client'

Open avinashs2401 opened this issue 3 years ago • 4 comments

Hi, In my angular application I faced the ansi-html vulnerability issue (No direct dependency of ansi-html in my project, it's an inner dependency of other packages) and I did the following in package.json to force resolve to ansi-html-community,

"resolutions": {
    "ansi-html": "https://registry.npmjs.org/ansi-html-community/-/ansi-html-community-0.0.8.tgz"
}
 "scripts": {
    "preinstall": "npx npm-force-resolutions"
  }

The package-lock.json now has the ansi-html-community only and not ansi-html. But when I run the application, I get the following error,

Error: (webpack)-dev-server/client/overlay.js Module not found: Error: Can't resolve 'ansi-html' in '..../node_modules/webpack-dev-server/client'

Please help on this.

avinashs2401 avatar Mar 16 '22 08:03 avinashs2401

Hi @avinashs2401, did you change the import as well? you should import it like this:

import ansiHTML from "ansi-html-community";

Read more here.

Let me know if it's solved or not!

mahdyar avatar Mar 16 '22 21:03 mahdyar

@mahdyar I'm not using the ansiHtml explicitly anywhere in my project. It's an inner dependency of webpack-dev-server which in turn is a dependency of @angular-devkit/build-angular

avinashs2401 avatar Mar 17 '22 04:03 avinashs2401

@mahdyar I'm not using the ansiHtml explicitly anywhere in my project. It's an inner dependency of webpack-dev-server which in turn is a dependency of @angular-devkit/build-angular

Would you try with overrides to see if it works? https://github.com/Tjatse/ansi-html/issues/19#issuecomment-1048337364

mahdyar avatar Mar 17 '22 10:03 mahdyar

@mahdyar No. That's not working as well. So the problem I'm facing is exactly described here by someone - https://stackoverflow.com/questions/64605805/npm-force-resolutions-not-working-when-installing-a-new-package. Initially when I delete node_modules and run npm install. There is no trace of ansi-html in the resolved packages. But when I run the application I face the error described above. Again, when I simply give another npm install (maybe for installing a new package (or) just simply one more npm install without any change), ansi-html 0.0.7 comes into play as one of the dependencies in webpack-dev-server and the "resolutions" or "overrides" in package.json is not taken into account. But this time the application runs without issues as its able to find ansi-html.

avinashs2401 avatar Mar 18 '22 06:03 avinashs2401