question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript cannot locate the type information of the core module.

See original GitHub issue

Hi there 👋

I’d like to import the core and only necessary language files. I tried as below but then realised that there is something wrong in package regarding typings.

import hljs from 'highlight.js/lib/core'
import javascript from 'highlight.js/lib/languages/javascript'
Could not find a declaration file for module 'highlight.js/lib/core'. 

I have not imported the index module i.e. import hljs from 'highlight.js. So, typescript can’t locate the type information for the core module from a subfolder. I believe the solution might be creating .d.ts file for every subfolder and file in your case.

I quickly fixed this issue locally by creating a core.d.ts file under lib directory. So, I guess we need to declare the entire API that the library exposes.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:37 (24 by maintainers)

github_iconTop GitHub Comments

2reactions
blujediscommented, May 22, 2021

FYI setting reference seems to play nice as near as I can tell.

In my case the file importing core is in src/filename.ts

/// <reference path="../node_modules/highlight.js/types/index.d.ts" />
import hljs from 'highlight.js/lib/core';

From there register your languages:

import typescript from 'highlight.js/lib/languages/typescript';
hljs.registerLanguage('typescript', typescript);
1reaction
firelizzard18commented, Apr 5, 2021

@joshgoebel When I ran cp -r /tmp/highlight.js/build ./node_modules/highlight.js, it worked

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'X' Error in TypeScript | bobbyhadz
The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project....
Read more >
Cannot find module 'react' or its corresponding type ...
When I change the file's extension to .js and .jsx from.ts and .tsx, the errors disappear. How should I solve this problem for...
Read more >
Documentation - Module Resolution - TypeScript
This section assumes some basic knowledge about modules. Please see the Modules documentation for more information. Module resolution is the process the ...
Read more >
TypeScript error in Visual Studio – Cannot find module ...
Experimental support for decorators is a feature that is subject to change in a future release. · Cannot find module '@angular/core' · Cannot...
Read more >
How to fix error TS7016: Could not find a declaration file for ...
How to fix error TS7016: Could not find a declaration file for module 'XYZ'. 'file.js' implicitly has an 'any' type ... If you're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found