I am currently learning to use nodejs with express as my franework and handlebar as the template engine.
PS: This is from the chartjs tutorial where they use parcel.
When I am trying to do the same with express (node src/app.js) I am getting an error Failed to resolve module specifier "chart.js/auto"
I have noticed couple of times where I am not able to import modules in external js files. Is there a way to import modules in external js files or is it that express in particular is unable to the same.
I have already npm installed chartjs. I have a page index.hbs
<!doctype html>
<html lang="en">
<head>
<title>Chart.js example</title>
</head>
<body>
<div style="width: 800px;"><canvas id="acquisitions"></canvas></div>
<script type="module" src="./js/acquisitions.js"></script>
</body>
</html>
and acquisitions.js
import Chart from 'chart.js/auto'
(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: 'bar',
data: {
labels: data.map(row => row.year),
datasets: [
{
label: 'Acquisitions by year',
data: data.map(row => row.count)
}
]
}
}
);
})();