Skip to content

createResolver

createResolver allows you to resolve paths relative to your integration’s location, eliminating the need to manage complex package.json exports for file references. It takes a base URL (typically import.meta.url) and returns a resolve function that can create absolute paths relative to that location:

We recommend calling createResolver in your integration’s setup function to easily access resolve in any hook.

  1. Create the resolver

    Always pass import.meta.url to createResolver - this is the equivalent of the old __filename and ensures paths work correctly regardless of installation location:

    const { resolve } = createResolver(import.meta.url);
  2. Use the resolve function

    Use resolve() with relative paths to reference files in your integration:

    integration/index.ts
    import type { AstroIntegration } from "astro";
    import { createResolver } from "astro-integration-kit";
    export default function myIntegration(): AstroIntegration {
    const { resolve } = createResolver(import.meta.url);
    return {
    name: "my-integration",
    hooks: {
    "astro:config:setup": ({ injectRoute }) => {
    injectRoute({
    pattern: "/my-route",
    entrypoint: resolve("./pages/my-route.astro")
    });
    }
    }
    }
    }