ngx-highlightjs: Highlight.js library was not imported and cannot read property 'themePath' of undefined

  • bug report
  • feature request
  • question

Repro steps

  1. Install ngx-hightlightjs 6.1.0

  2. Add the following to app.module.ts:

import {HighlightModule, HIGHLIGHT_OPTIONS} from 'ngx-highlightjs';

imports: [
    ...
    HighlightModule
  ],
providers: [
    ...
    {
      provide: HIGHLIGHT_OPTIONS,
      useValue: {
        coreLibraryLoader: () => import('highlight.js/lib/core'),
        languages: {
          xml: () => import('highlight.js/lib/languages/xml')
        }
      }
    }
  ],

Console logs

image

Debug mode : image

Environment

  • Angular: 13
  • ngx-highlightjs: 6.1.0
  • Browser(s): Chrome 87.0.4280.141 (Build officiel) (32 bits)
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10 Professionnel

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16 (7 by maintainers)

Most upvoted comments

This error is because your project is missing the original package npm i highlight.js

It is weird because it should be installed automatically!

Not really! the only thing that matters is that it should not load the script twice if the highlight module is being used in different lazy modules. that’s why I choice a singleton service.