chartjs / chartjs/Chart.js

Safari 12.1.2 getting error Unexpected token '='. Expected an opening '(' before a method's parameter list

Open
#11,408 6 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

All the charts should work on older safar browsers like 12.1.12``

### Current behavior

Using Tree shaking to build using "npm run build" the donut chart works in latest safari but does not work on version safari 12.1.12

issue is similar to #11028 , but it is not working on chartjs 4.3.0 using below code

vi ./src/acquisitions.js

import {
Chart,
Colors,
BarController,
CategoryScale,
LinearScale,
BarElement,
DoughnutController,
ArcElement,
Legend,
Title
} from 'chart.js'

Chart.register(
Colors,
BarController,
BarElement,
CategoryScale,
LinearScale,
DoughnutController,
ArcElement,
Legend,
Title
);
export {Chart}

vi src/index.html


Chart.js example






import {Chart} from './acquisitions.js'
(async function() {
const data = [
{ year: 2010, count: 10 },
{ year: 2011, count: 20 },
{ year: 2012, count: 15 },
{ year: 2013, count: 25 },
{ year: 2014, count: 22 },
{ year: 2015, count: 30 },
{ year: 2016, count: 28 },
];

new Chart(
document.getElementById('acquisitions'),
{
type: 'doughnut',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]
}
]
},
options: {
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
}
}
);
})();

then i run npm run build

### Reproducible sample

using above code mentioned

### Optional extra steps/info to reproduce

home/akshaypunja/.nvm/versions/node/v20.3.1/lib
├── are-you-es5@2.1.2
├── corepack@0.18.0
├── node-gyp@9.4.0
├── node-pre-gyp@0.17.0
└── npm@9.7.2

### Possible solution

what changes i should do to ./src/acquisitions.js so that it supports older browser

### Context

_No response_

### chart.js version

v4.3.0

### Browser name and version

Safari 12.1.12

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.