Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular 18 with SSR: Setting optimization to true ignores library loaded inside scripts

My Angular 18 application runs smoothly with SSR in development mode. However, when I switch to production mode with optimization set to true, the application fails to locate the 'igv.js' file, even though it is already included in the scripts section of the angular.json file.

Configurations section:

  "configurations": {
    "production": {
      "budgets": [
        {
          "type": "anyComponentStyle",
          "maximumWarning": "6kb"
        }
      ],
      "optimization": true,
      "sourceMap": true,
      "namedChunks": true,
      "extractLicenses": true,
      "outputHashing": "all"
    },
    "development": {
      "optimization": false,
      "extractLicenses": false,
      "sourceMap": true
    }
  },

Scripts section:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    "scripts": [
      "node_modules/swagger-ui-dist/swagger-ui-bundle.js",
      "node_modules/swagger-ui-dist/swagger-ui-standalone-preset.js",
      "igv.js"
    ],

This is how I am calling the IGV module. Since I am using SSR, I have to call the file on the client-side.

 ngAfterViewInit() {
    if (this.isBrowser) {
      import('igv').then(igvModule => {
        const igv = igvModule.default;
        if (igv && typeof igv.createBrowser === 'function') {
          this.igvModule = igv;
        } else {
          console.error('igv.createBrowser is not a function');
        }
      }).catch(error => {
        console.error('Error loading igv module:', error);
      });
    }
  }

Any suggestion on what could be missing?

>Solution :

Could you try importing igv directly using the below import and start using it on your components?

import igv from '../node_modules/igv/dist/igv.esm.js';

Related github issue

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading