{"id":25455,"library":"esbuild-svelte-inertia","title":"esbuild-svelte-inertia","description":"A tiny esbuild plugin (v0.0.5, updated Dec 2022, no regular release schedule) that enables importing Svelte page components via glob patterns for use with Inertia.js. It removes the need for manual page registration by resolving dynamic imports. Intended for esbuild-based Svelte + Inertia projects. Minimal and focused, but unmaintained since initial release.","status":"active","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/BilalBudhani/esbuild-svelte-inertia","tags":["javascript","esbuild","svelte","inertia"],"install":[{"cmd":"npm install esbuild-svelte-inertia","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-svelte-inertia","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-svelte-inertia","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin to work","package":"esbuild","optional":false}],"imports":[{"note":"Package only provides CommonJS; no ESM export. Use require() in Node.js or configure bundler to handle CJS.","wrong":"import svelteInertiaPlugin from 'esbuild-svelte-inertia'","symbol":"default export","correct":"const svelteInertiaPlugin = require('esbuild-svelte-inertia')"},{"note":"The glob import must use namespace import syntax. Also ensure the glob pattern is supported by esbuild (no external plugin).","wrong":"import pages from './Pages/**/*'","symbol":"pages import","correct":"import * as pages from './Pages/**/*'"},{"note":"The plugin is a function that must be called (with no arguments). Pair with the official svelte plugin.","wrong":"plugins: [svelteInertiaPlugin, sveltePlugin]","symbol":"plugin usage","correct":"plugins: [sveltePlugin(), svelteInertiaPlugin()]"}],"quickstart":{"code":"// esbuild.config.js\nconst esbuild = require('esbuild');\nconst sveltePlugin = require('esbuild-svelte');\nconst svelteInertiaPlugin = require('esbuild-svelte-inertia');\n\n// Ensure your svelte.config.js has the inertiakit adapter or handle SPA mode\n\nasync function build() {\n  await esbuild.build({\n    entryPoints: ['src/main.js'],\n    bundle: true,\n    outdir: 'public/build',\n    plugins: [sveltePlugin(), svelteInertiaPlugin()],\n  });\n}\n\nbuild().catch(() => process.exit(1));\n\n// Example main.js using Inertia\nimport { createInertiaApp } from '@inertiajs/inertia-svelte';\nimport * as pages from './src/Pages/**/*';\n\ncreateInertiaApp({\n  resolve: name => pages[name.replace('/', '')],\n  setup({ el, App, props }) {\n    new App({ target: el, props });\n  },\n});","lang":"javascript","description":"Minimal setup: esbuild config with both svelte and inertia plugins, then import pages via glob for Inertia resolve."},"warnings":[{"fix":"Ensure all Svelte page components have .svelte extension and the pattern matches directory structure exactly.","message":"The glob import pattern './Pages/**/*' may not work as expected if your project is bundled with esbuild without the 'copy' plugin for static files. Only .svelte files are picked up.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use require() in CommonJS context, or configure your project to convert CJS to ESM (e.g., esbuild's --format=esm with CJS shims).","message":"Plugin is CommonJS only; importing via ESM 'import' will cause 'require is not defined' error if Node ES modules mode is used.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Modify resolve: name => pages['./' + name.replace('./Pages/', '').replace('.svelte', '')] or use a custom resolver.","message":"The plugin does not handle nested page directories reliably; the replace('/','') may break if pages have subfolders (e.g., 'Admin/Dashboard').","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'const svelteInertiaPlugin = require(\"esbuild-svelte-inertia\")' instead of import.","cause":"Using ESM import syntax for a CJS-only module.","error":"TypeError: require(...) is not a function"},{"fix":"Add 'svelteInertiaPlugin()' to the plugins array. Also ensure the directory './Pages' exists relative to the entry point.","cause":"Glob pattern not resolved; esbuild needs the plugin to handle the glob import.","error":"Error: Cannot find module './Pages/**/*'"},{"fix":"Check the exact keys: log 'pages' to see the shape. Common fix: use 'name.replace('/', '').replace('.svelte', '')'.","cause":"Page name does not match key in the imported pages object (likely due to path prefix or extension).","error":"TypeError: pages[name.replace(...)] is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}