MurhafSousli / ngx-highlightjs

Angular syntax highlighting module

Home Page:https://ngx-highlight.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This repo not support pnpm

BppleMan opened this issue · comments

Reproduction

#this is typo:
pnpm i ngx-highlightjk
#actual:
pnpm i ngx-highlightjs

#when i use npm i ngx-highlightjs,then everything will be better

ng serve

Expected Behavior

run project

Actual Behavior

./src/main.ts:8:31-53 - Error: Module not found: Error: Can't resolve 'highlight.js' in '/Users/bppleman/coolbox/coolbox-gui/src'

Error: src/main.ts:11:49 - error TS2307: Cannot find module 'highlight.js' or its corresponding type declarations.

11                 fullLibraryLoader: () => import("highlight.js"),
                                                   ~~~~~~~~~~~~~~

Environment

  • Angular: 16.2.0
  • ngx-highlightjs: 10.0.0
  • Browser(s): nothing
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

its ngx-highlightjs

its ngx-highlightjs

@MurhafSousli

That's a typo, but the problem remains

I don't use pnpm, shouldn't it work like yarn? or I have to publish the package to pnpm?

@MurhafSousli I think the problem is with highlight.js resolving. pnpm or yarn pnp doesn't linking it.

Possible solution is installing directly to project:
pnpm install highlight.js

@MurhafSousli second option:

add to .npmrc:
public-hoist-pattern[]=*highlight.js*

@MurhafSousli so the idea is to make ngx-highlightjs works like solid package. Library should work like line-numbers

example:

coreLibraryLoader: () => import('highlight.js/lib/core'),
languages: {
  css: () => import('highlight.js/lib/languages/css'),
  scss: () => import('highlight.js/lib/languages/scss'),
  typescript: () => import('highlight.js/lib/languages/typescript'),
  xml: () => import('highlight.js/lib/languages/xml'),
},

should be replaced with:

coreLibraryLoader: () => import('ngx-highlightjs/highlight-lib'),
languages: {
  css: () => import('ngx-highlightjs/languages/css'),
  scss: () => import('ngx-highlightjs/languages/scss'),
  typescript: () => import('ngx-highlightjs/languages/typescript'),
  xml: () => import('ngx-highlightjs/languages/xml'),
},

This is a dependency, how can you receive updates and fixes from the main package then?

@MurhafSousli
pnpm uses linking to node_modules: Flat node_modules is not the only way

So, for libraries there are 2 approaches:

  • Add instructions for pnpm: as i said
    • users needs to install highlight.js directly to their projects
    • or add public-hoist-pattern[]=*highlight.js* to .npmrc
  • Add re exports:
    •  const core = import('highlight.js/lib/core');
       export default core;
      

I am afraid this is out of the scope for this project.

This is just a wrapper package of highlight.js and it depends on it, it works the standard npm. for other tools - developers should figure it out on their own.