highlight.js: Module not found: Error: Package path ./highlight.min.js is not exported from package @highlightjs\cdn-assets
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/*"
}
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (7 by maintainers)
Commits related to this issue
- (fix) do not restrict exports from cdn-assets - Resolves #3223 — committed to joshgoebel/highlight.js by joshgoebel 3 years ago
- (fix) do not restrict exports from cdn-assets - Resolves #3223 — committed to highlightjs/highlight.js by joshgoebel 3 years ago
Using a separate variable to store the module name seems to have fixed this for me. So instead of
you would use:
I have no idea why and if this actully works. Fixes my build and the example in the webpack issue though.
This seems to be broken for me as well. I’m getting the following error message:
This message appears when using the dynamic import syntax
The following are all solutions that fix the problem for me:
Removing the
exportsfield frompackage.jsonAdding one more export as follows:
Downgrading to the latest v10 release fixes this problem for me. Removing the
exportsfrom v11 also fixes the problem. So something about theexportskey in thepackage.jsonfor v11 has to be the cause.Framework: Vue 3 (Vue CLI 5) Language: TypeScript Bundler: Webpack 5 Node: 14 npm: 7
I realize that. That’s why I suggested file a bug against your packaging software. Of course you can link to this issue and we’ll see where things land.
Resolved with release of 11.0.1.
Exports are no longer restricted for
cdn-assets, as this was never the intention.I found that as long as it is imported in this way, it works normally.