When this code runs:
// index.svelte
import Chart, { Tooltip } from 'chart.js/auto.esm';
console.log({ Tooltip });
Tooltip
is successfully output to the console, but I also get an error (in the browser):
The requested module '/node_modules/.vite/chart_js_auto.js?v=9674d8be' does not provide an export named 'Tooltip'
So SvelteKit is obviously running this code multiple times. Why does it work once, then fail later? How do I get it to work all the time?
I imported 'chart.js/auto.esm'
instead of just 'chart.js'
because SvelteKit needs ESM modules. I can import { Tooltip } from 'chart.js'
and this works locally, but a there's a different build error on Vercel:
SyntaxError: Named export 'Tooltip' not found. The requested module 'chart.js' is a CommonJS module, which may not support all module.exports as named exports.