chartjs / chartjs/chartjs-plugin-zoom

Hammer import crashes Rollup build (ESM version)

Open
#917 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
623
Forks
331
Avg merge
7h 5m
Merged PRs (30d)
7

Description

I integrate the Zoom plugin in my code like this:
```js
import zoomPlugin from 'chartjs-plugin-zoom';
```

Then I run a Rollup build:
```
npm run build
```

The build crashes with the following error:

![crash](https://github.com/user-attachments/assets/29442dbc-d8b9-4eee-967b-d2e73cb61900)

In order to fix the build, I go manually edit [chartjs-plugin-zoom.esm.js](https://www.npmjs.com/package/chartjs-plugin-zoom?activeTab=code) and replace line 7:
```js
import Hammer from 'hammerjs';
```

with
```js
import 'hammerjs';
```

I could not find an official guide how to integrate Hammer ESM package, but [this Stackoverflow answer](https://stackoverflow.com/a/41322757/9812865) seems to have a lot of votes and here I found the solution.

If would be great to fix this in the source code, so this fix doesn't have to be done manually after every install or update of the npm package.

Contributor guide

Open the contributing guide

Research direction

Run npm run build to reproduce the Rollup failure, then trace chartjs-plugin-zoom.esm.js back to the source import and inspect the Rollup build entry point. Done means the ESM package builds successfully with the Hammer integration and no manual edit is needed after installation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rollup
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.