#Why is my import not working? I'm making a custom plugin for a new file extension

4 messages · Page 1 of 1 (latest)

daring vector
#

my import is rendered in the HTML as plain text as if my .astro file were .html

velvet crowBOT
#

Hi @daring vector. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

It sounds like Astro isn’t recognizing your file as an Astro component, so the import is being output as literal text (behavior you’d see if the file were treated as plain HTML). Check these common causes:

  • Wrong file type/location: Only .astro files under src/pages/ or imported into Astro components are parsed as Astro. A .html file in src/pages/ is served as-is and won’t process imports (so imports will appear as text) (HTML Pages).
  • Unsupported extension without a parser: If you’re introducing a new file extension via a custom plugin, Astro/Vite must know how to handle it. By default, Astro only supports specific file types. To add a new one, use a Vite/Rollup plugin that transforms that extension into something importable (e.g., JS or JSON) and configure it in astro.config.mjs (Imports reference; Extending file type support).
  • Missing plugin setup: Ensure your custom plugin runs in Vite’s pipeline (vite.plugins in astro.config.mjs) and actually returns a module export for your new extension, similar to how the YAML recipe wires @rollup/plugin-yaml to make .yml importable (Installing a Vite or Rollup plugin).
  • Bad import path or type-only import: A wrong path or importing a TypeScript type as a value can trigger “Could not import file” errors; double-check paths and mark type imports with import type (Could not import file; Import statements).
#

If your goal is to create pages using your new extension with Astro syntax, Astro itself cannot parse arbitrary new “Astro-like” syntaxes just by adding a plugin—.astro parsing is built-in. For custom data/file imports, add a plugin that turns your new files into JS/JSON modules, then import them into .astro files. If you instead created .html pages expecting Astro imports to work, convert them to .astro so imports are processed (HTML Pages).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: