0

I have two Angular projects: main and library. Once in a time I make some changes to the library. And before uploading it to NPM I would like to check if it will run well on my main project with other packages. And what I am doing is just building my lib project after changes, take those built files(from dist folder) and replace them with one in node_modules of my main project. But my Angular app doesn`t see those changes. I know that its not good practice at all to modify node_modules but still.

I have playground in my library project where I test it but I would like to see how it works in my main project with other packages.


Is there any other ways how I can test my library BEFORE publishing it to NPM? OR Is it possible to make Angular see those changes in node_modules?

JSON Derulo
  • 9,780
  • 7
  • 39
  • 56
  • 1
    Does this answer your question? [Build and use npm package locally](https://stackoverflow.com/questions/55560791/build-and-use-npm-package-locally) – JSON Derulo May 17 '23 at 08:02
  • 1
    The question I linked is the proper solution. A workaround would be to clear the `.angular` folder or to completely disable Angular's caching mechanism. The problem you are facing is that Angular caches the node modules, and if you change the files inside, they will still use the code from cache. Only if the version changes, the files are evaluated again. – JSON Derulo May 17 '23 at 08:04
  • You can use [`ng-packagr`](https://www.npmjs.com/package/ng-packagr). – Jai May 17 '23 at 08:08
  • @Jai As far as I understand the question, it doesn't matter whether it's a library built with ng-packagr or just a basic JavaScript package. The root problem is caused by Angular's caching of the node_modules. – JSON Derulo May 17 '23 at 08:13
  • @JSONDerulo is right. It doesn't matter whether it's a lib built with ng-packagr or not. Let me check the offered solution above:) – Yegor Petrov May 17 '23 at 08:33
  • @JSONDerulo It worked, thanks! The answer you dropped above solves problem but the point is that I also had to clear my Angular cache and after that I was able to check my lib before uploading to NPM. Please add your answer so I can mark it as a solution. – Yegor Petrov May 19 '23 at 11:50

1 Answers1

1

The problem is that Angular does some caching to improve the build performance. When modifying files inside the node_modules, but the version of the package stays the same, Angular uses the cached version and will not respect the changes to the files.

The proper solution to this problem is to locally pack the package, and installed the packed package in your project, as described in this answer.

Alternatively you can clean the cache by running ng cache clean. If you want to completely disable the cache, you can run ng cache disable. Please note that with this approach you will see higher build times of subsequent builds.

JSON Derulo
  • 9,780
  • 7
  • 39
  • 56