← All tasks
javascripthighlightjs/highlight.js #3827Not a task: not reproduced

vite/rollup tree shakes lib/common.js

envgap__highlightjs__highlight.js-3827

01 / FAILURE SIGNATURE

As reported upstream

No identifying execution failure has been captured.
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
7fb52a23ea43bc06210569b794331436e1b2587b
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

highlightjs/highlight.js #3827 · read the original issue
**Describe the issue/behavior that seems buggy**



I investigated a few issues (e.g. https://github.com/highlightjs/vue-plugin/issues/44) reported in the `vue-plugin` repo where production builds are stripping out `import 'highlight.js/lib/common';` side effect imports 



Turns out vite (which uses rollup internally) tree shakes side effect imports if the files themselves are not marked as side effect in `package.json`



**Sample Code or Instructions to Reproduce**



```

npm create vite@latest

npm install highlight.js

```



Then inside `src/main.ts`, add:



```

import 'highlight.js/lib/common'

import hljs from 'highlight.js/lib/core'

console.log(hljs.listLanguages())

```



In debug builds `npm run dev`, it should list all languages registered inside `highlight.js/lib/common`



However in production builds `npm run build && npm run preview`, it will print an empty array.



**Expected behavior**



Should print all languages in both debug/production builds



**Additional context**



This package.json should be updated to:



```

  "sideEffects": [

    "./es/common.js",

    "./lib/common.js",

    "*.css",

    "*.scss"

  ],

```

Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]