Reputation: 13077
I need to import a simple string into an astro starlight MDX file to show the latest version number. My code is basically
---
title Version Test
desc Show version
---
import VERSION from "/src/components/version";
Version {VERSION}
and version.js
is just
export const VERSION = '1.0.0'
I'm able to successfully import this into a .astro file, but in my MDX file it is loading as undefined and not logging any error messages.
How can I import this simple string into my MDX file?
Upvotes: 0
Views: 154
Reputation: 816
The problem is the import type. You exported a named const and need import as named on the MDX file, like Dogbert suggested in a comment:
Try
import {VERSION} from "/src/components/version";
braces aroundVERSION
.
I forked an example for MDX from the Astro's github examples and modified for your case on the StackBlitz.
Upvotes: 1
Reputation: 222198
To import a named export in ES6 modules, you need to use destructuring in the import call:
import { VERSION } from "/src/components/version";
Version {VERSION}
Upvotes: 0