Liferay js bundler - unused node modules not removed

152 views Asked by At

I am using Liferay 7.3.5 and building an Angular Portlet. I am finding it very difficult to experiment with different modules (or versions of the same module) because, somehow, the final jar OSGI module does contain all the modules I have been played with and not the only ones that are in the package.json file.

As an example, I have added "ng2-pdf-viewer": "5.3.4" and then switched it to "ng2-pdf-viewer": "6.3.0". I was expecting that the final jar file to contain only the 6.3.0 version, but it actually contains both - the 5.3.4 and 6.3.0. This happens for all the other modules I have been playing with. So, basically, what I have in the package.json file is not reflected in the final .jar file and I am not sure how to clear the cache that is just keeping all unused dependencies.

I have also removed all folders from the node_modules folder, but no success afterward.

How can I purge/clean the context in order to have a real state?

1

There are 1 answers

0
Victor On BEST ANSWER

I did not find a full solution, but it is something that worked enough for me - I have done the following:

  1. delete node_modules folder from eclipse-workspace<your_project_name>\modules<your_module_name>
  2. executed gradle clean from eclipse gradle tasks (this will clean the build folder of the project and doesn't anything to do with the node_modules folder)
  3. executed npm install from eclipse-workspace<your_project_name>\modules<your_module_name>
  4. build again full project

Important notes: I have also noticed that, even though I have made all this cleaning above, there were desynchronizations between my package.json and package-lock.json - I mean, I had version "ng2-pdf-viewer": "5.2.3" in package.json file, but in the generated package-lock.json I had "ng2-pdf-viewer": "5.3.4". I have just triggered twice the build process and in the end the files synched. Even though the package-lock.json file was correct this time, both modules were packed in the Liferay module .jar - I mean, there were both 5.2.3 and 5.3.4 versions. I could only keep one of them when I switch in the package.json file to the newer version.