A little late to the party, but here's how I was able to achieve an answer to OP's question as of (14 Apr 23).
As per the sveltekit docs.
// add the following to > svelte.config.js
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
const file = fileURLToPath(new URL('package.json', import.meta.url));
const json = readFileSync(file, 'utf8');
const pkg = JSON.parse(json);
As well as;
// add the following to kit: {}
version: {
name: pkg.version
}
Then in your desired component;
<script>
import { version } from '$app/environment';
</script>
<span>The package.json version is: {version}</span>
If you're planning to go the Vite route, you should read, urb_'s answer to a similar question asked here on S.O. How do I add a version number to a SvelteKit/Vite app?.
but in summary;
Be aware, config changed after @sveltejs/[email protected]: After a
breaking change on @sveltejs/[email protected], Vite config must be
included in its own file:
VERSION
and avoidVERSION is not defined
error messages? (using SvelteKit) – Budgerigar