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.

Module not found: Error: Package path ./highlight.min.js is not exported from package @highlightjs\cdn-assets

See original GitHub issue

Describe the issue/behavior that seems buggy

Module not found: Error: Package path ./highlight.min.js is not exported from package D:\Documents\github\markdown-reader\node_modules@highlightjs\cdn-assets (see exports field in D:\Documents\github\markdown-reader\node_modules@highlightjs\cdn-assets\package.json)

Sample Code or Instructions to Reproduce

import hljs from "@highlightjs/cdn-assets/highlight.min.js";

export default hljs;

Expected behavior

Additional context

webpack 5.38.1 @highlightjs/cdn-assets 11.0.0

{
   "exports": {
      ".": {
         "require": "./lib/index.js",
         "import": "./es/index.js"
      },
      "./package.json": "./package.json",
      "./lib/common": {
         "require": "./lib/common.js",
         "import": "./es/common.js"
      },
      "./lib/core": {
         "require": "./lib/core.js",
         "import": "./es/core.js"
      },
      "./lib/languages/*": {
         "require": "./lib/languages/*.js",
         "import": "./es/languages/*.js"
      },
      "./scss/*": "./scss/*",
      "./styles/*": "./styles/*",
      "./types/*": "./types/*"
   }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
azulcommented, Oct 27, 2021

Using a separate variable to store the module name seems to have fixed this for me. So instead of

await import(
  /*
   webpackInclude: /(java|javascript|latex|markdown|python|ruby|typescript|xml|yaml)/,
   webpackChunkName: "lang-[request]"
   */
   `highlight.js/lib/languages/${lang}.js`
)

you would use:

const moduleName = `highlight.js/lib/languages/${lang}.js`
await import(
  /*
   webpackInclude: /(java|javascript|latex|markdown|python|ruby|typescript|xml|yaml)/,
   webpackChunkName: "lang-[request]"
   */
   moduleName
)

I have no idea why and if this actully works. Fixes my build and the example in the webpack issue though.

5reactions
dhruvkbcommented, Jul 26, 2021

This seems to be broken for me as well. I’m getting the following error message:

Module not found: Error: Package path ./lib/languages is not exported from package <path_to_proj>/node_modules/highlight.js (see exports field in <path_to_proj>/node_modules/highlight.js/package.json)

This message appears when using the dynamic import syntax

await import(
  /*
   webpackInclude: /(java|javascript|latex|markdown|python|ruby|typescript|xml|yaml)/,
   webpackChunkName: "lang-[request]"
   */
   `highlight.js/lib/languages/${lang}.js`
)

The following are all solutions that fix the problem for me:

  1. Removing the exports field from package.json

  2. Adding one more export as follows:

     "./lib/languages/*": {
       "require": "./lib/languages/*.js",
       "import": "./es/languages/*.js"
     },
+    "./lib/languages": {
+      "require": "./lib/languages",
+      "import": "./es/languages"
+    },
  1. Referencing from as a relative path from the project directory also works:
 await import(
   /*
    webpackInclude: /(java|javascript|latex|markdown|python|ruby|typescript|xml|yaml)/,
    webpackChunkName: "lang-[request]"
    */
-   `highlight.js/lib/languages/${lang}.js`
+   `@/../node_modules/highlight.js/lib/languages/${lang}.js`
 )
  1. Downgrading to v10. This isn’t really a solution but it used to work before so, as this works as a last resort.

Downgrading to the latest v10 release fixes this problem for me. Removing the exports from v11 also fixes the problem. So something about the exports key in the package.json for v11 has to be the cause.

Framework: Vue 3 (Vue CLI 5) Language: TypeScript Bundler: Webpack 5 Node: 14 npm: 7

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Package path . is not exported from ...
In the relevant .js script import Firestore and Firebase as follows: ... Even after doing that you will get error of module not...
Read more >
highlight.js
Syntax highlighting for the Web ... multi-language code highlighting; available for node.js; works with any markup; compatible with any js framework.
Read more >
auroralabs - Laracasts
Hi, Im trying to import some Swiper 7 modules into a projct and when i hit mix the following exception is thrown Module...
Read more >
@joshgoebel/highlight.js-cdn-assets - npm package | Snyk
The npm package @joshgoebel/highlight.js-cdn-assets was scanned for known vulnerabilities and missing license, and no issues were found. Thus ...
Read more >
highlight.js - npm
This will find and highlight code inside of <pre><code> tags; it tries to detect the language automatically. If automatic detection doesn't ...
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