Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find a declaration file for module 'highlightjs-line-numbers.js' - Show line numbers #234

Closed
alebuffoli opened this issue Sep 16, 2022 · 6 comments · Fixed by #261
Labels

Comments

@alebuffoli
Copy link

Expected Behavior

Show line numbers

Actual Behavior

Every time I try to import the library highlightjs-line-numbers.js to show the line numbers in the app module like this:

providers: [
     ...
    {
      provide: HIGHLIGHT_OPTIONS,
      useValue: <HighlightOptions>{
        lineNumber: true,
        coreLibraryLoader: () => import('highlight.js/lib/core'),
        lineNumbersLoader: () => import('highlightjs-line-numbers.js'),
        themePath: 'node_modules/highlight.js/styles/github.css',
        languages: {
          typescript: () => import('highlight.js/lib/languages/typescript'),
          css: () => import('highlight.js/lib/languages/css'),
          xml: () => import('highlight.js/lib/languages/xml'),
        },
      },
    },
  ],

it gives me the error:

Error: src/app/app.module.ts:69:41 - error TS7016: Could not find a declaration file for module 'highlightjs-line-numbers.js'. '/Users/alessandrobuffoli/Development/Blockchain/Solana/app.cowsigner/node_modules/highlightjs-line-numbers.js/src/highlightjs-line-numbers.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/highlightjs-line-numbers.js` if it exists or add a new declaration (.d.ts) file containing `declare module 'highlightjs-line-numbers.js';`

69         lineNumbersLoader: () => import('highlightjs-line-numbers.js'),

Even if I've added and installed the following libraries in the package.json


    "highlight.js": "^11.5.1",
    "highlightjs-line-numbers.js": "^2.8.0",
    "ngx-highlightjs": "^7.0.0",

Shouldn't it be written in the docs how to install everything?

Environment

  • Angular: 14.0.0
  • ngx-highlightjs: 7.0.1
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): MacOS
@alebuffoli alebuffoli changed the title How to show line numbers Could not find a declaration file for module 'highlightjs-line-numbers.js' - Show line numbers Sep 16, 2022
@MurhafSousli
Copy link
Owner

I think you modified something in your tsconfig.json, google the general error without mentioning the library or try it out in a brand new angular project

@gRoussac
Copy link

gRoussac commented Sep 21, 2022

Hi, +1

It seems a types declaration file is missing ? adding highlightjs-line-numbers.d.ts in the src folder as suggested lets you at least compile. It's also happening on https://stackblitz.com/edit/ngx-highlightjs .

@orojasm
Copy link

orojasm commented Oct 21, 2022

In fact, the file "highlightjs-line-numbers.d.ts" is missing, I created this file in the "src" directory with the following content:
declare module 'highlightjs-line-numbers.js';
Also copy file "node_modules/highlightjs-line-numbers.js/src/highlightjs-line-numbers.js" to "node_modules/highlightjs-line-numbers.js/dist/highlightjs-line-numbers.js", this is due to with the file highlightjs-line-numbers.min.js did not work for typescript types

@Ryo112358
Copy link

Still running into this issue in the latest major version (8.0.0)

Environment

  • Angular: 15.2.0
  • ngx-highlightjs: 8.0.0
  • Browser(s): Chrome
  • Operating System: Windows 11

@pmrelvas
Copy link

pmrelvas commented Jun 24, 2023

hey, having the same issue:

  • angular: 15.2.7
  • ngx-highlightjs: 9.0.0
  • browser: Chrome
  • Operative System: Mac Os Ventura
  • typescript: 4.9.4

@MurhafSousli
Copy link
Owner

I've included the script within ngx-highlightjs in v10

providers: [
  {
    provide: HIGHLIGHT_OPTIONS,
    useValue: {
      lineNumbersLoader: () => import('ngx-highlightjs/line-numbers')
    }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants