Using rollup with typescript and highlight.js

I’m trying to use rollup to build a bundle containing highlight.js.

This is the starter project I’m using to build the bundle. If we clone it and run:

git clone [email protected]:fireflysemantics/fs-lit-element-starter-ts.git b
cd b
npm i 
npm run rollup

We can see that the bundle is built without any errors.

And if we add highlight.js and import the default into src/my-dispatcher.component.ts, the following error is created.

npm i highlight.js

Import the default.

import hljs from "highlight.js";

Reference hljs on a property so that we don’t get any linting errors.

h:any = hljs;

If we now run npm run rollup again the following error is produced.

Thoughts?

./build/index.js → ./build/index.bundle.js...
(!) [plugin replace] @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
[!] RollupError: node_modules/highlight.js/es/index.js (2:7): "default" is not exported by "node_modules/highlight.js/lib/index.js", imported by "node_modules/highlight.js/es/index.js".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
node_modules/highlight.js/es/index.js (2:7)
1: // https://nodejs.org/api/packages.html#packages_writing_dual_packages_while_avoiding_or_minimizing_hazards
2: import HighlightJS from '../lib/index.js';
          ^
3: export { HighlightJS };
4: export default HighlightJS;
    at getRollupError (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/parseAst.js:282:41)
    at Object.error (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/parseAst.js:278:42)
    at Module.error (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:15321:28)
    at Module.traceVariable (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:15769:29)
    at ModuleScope.findVariable (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:13480:39)
    at Identifier.bind (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:8386:40)
    at ExportDefaultDeclaration.bind (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:6255:23)
    at Program.bind (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:6251:28)
    at Module.bindReferences (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:15302:18)
    at Graph.sortModules (/Users/oleersoy/Temp/b/node_modules/rollup/dist/shared/rollup.js:20535:20)

Just for reference this is the rollup configuration.

/**
 * @license
 * Copyright 2018 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */

import summary from 'rollup-plugin-summary';
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';

export default {
  input: './build/index.js',
  output: {
    file: './build/index.bundle.js',
    format: 'esm',
  },
  onwarn(warning) {
    if (warning.code !== 'THIS_IS_UNDEFINED') {
      console.error(`(!) ${warning.message}`);
    }
  },
  plugins: [
    replace({'Reflect.decorate': 'undefined'}),
    resolve(),
    /**
     * This minification setup serves the static site generation.
     * For bundling and minification, check the README.md file.
     */
    terser({
      ecma: 2021,
      module: true,
      warnings: true,
      mangle: {
        properties: {
          regex: /^__/,
        },
      },
    }),
    summary(),
  ],
};

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật