MurhafSousli / ngx-highlightjs

Angular syntax highlighting module
https://ngx-highlight.netlify.app/
MIT License
278 stars 35 forks source link

Function expressions are not supported in decorators #149

Closed edrorr closed 3 years ago

edrorr commented 4 years ago

Hello, I have installed ngx-highlight.js and following the provided instructions added this providers to my module

{
    provide: HIGHLIGHT_OPTIONS,
    useValue: {
        coreLibraryLoader: () => import('highlight.js/lib/core'),
        lineNumbersLoader: () => import('highlightjs-line-numbers.js'), // Optional, only if you want the line numbers
        languages: {
            xml: () => import('highlight.js/lib/languages/xml')
        }
    }
}

but when i run the project this errors are appearing :

Function expressions are not supported in decorators
Consider changing the function expression into an exported function.

so i have used the export function instead. but

export function loadHighlightJs() {
   return () => import('highlight.js/lib/core');
}

and changed the useValue inside provider to this :

coreLibraryLoader: loadHighlightJs()

The error is gone but HighlightJs is not working and i have this error in the browser Console : [HLJS] Highlight.js library was not imported!

OS and Version?

Windows 10

Versions

@angular/cli 10.2.0 node 12.19.0 npm 6.14.8

MurhafSousli commented 4 years ago

The issue is probably with the project setup you have, could be because the typescript version you are using... try it out with a a new angular project

matthewdolman commented 3 years ago

Did you ever fix this?

I am having the same issue.

Typescript 3.9.7 Angular 10.0.14 Angular CLI 10.0.8

edrorr commented 3 years ago

@matthewdolman No unfortunately i didn't had time and ended up importing the js file in angular.json

matthewdolman commented 3 years ago

try

coreLibraryLoader: loadHighlightJs

instead of

coreLibraryLoader: loadHighlightJs()

vinothd-toast commented 3 years ago

@matthewdolman No unfortunately i didn't had time and ended up importing the js file in angular.json

hii, iam getting the same error, what js do i need to add in angular.json file, iam using angular version 8

matthewdolman commented 3 years ago
providers: [
    {
      provide: HIGHLIGHT_OPTIONS,
      useValue: {
        coreLibraryLoader: coreLibraryLoader,
        lineNumbersLoader: lineNumbersLoader,  // Optional, only if you want the line numbers
        languages: {
          json: languageJSON
        }
      }
    }
  ]

app.module.ts

vinothd-toast commented 3 years ago
providers: [
    {
      provide: HIGHLIGHT_OPTIONS,
      useValue: {
        coreLibraryLoader: coreLibraryLoader,
        lineNumbersLoader: lineNumbersLoader,  // Optional, only if you want the line numbers
        languages: {
          json: languageJSON
        }
      }
    }
  ]

app.module.ts

i tried this way, and its says Highlight.js library was not imported! in browser console