{"id":20971,"library":"awilix-vite","title":"awilix-vite","description":"Awilix integration for Vite projects, version 2.0.3. Provides a `loadModules` function that bridges Awilix's module loading with Vite's `import.meta.glob` for automatic dependency registration. Unlike loadModules in awilix itself (which uses glob patterns and file system scanning), this plugin relies on Vite's static analysis for dynamic imports. Requires manual use of `import.meta.glob` and does not work with lazy glob patterns. Ships TypeScript types. Designed for client-side or SSR Vite setups.","status":"active","version":"2.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/kvist-no/awilix-vite","tags":["javascript","awilix","vite","dependency","injection","typescript"],"install":[{"cmd":"npm install awilix-vite","lang":"bash","label":"npm"},{"cmd":"yarn add awilix-vite","lang":"bash","label":"yarn"},{"cmd":"pnpm add awilix-vite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for container creation and resolver options","package":"awilix","optional":false}],"imports":[{"note":"ESM-only package; require() will fail. Use import.","wrong":"const loadModules = require('awilix-vite')","symbol":"loadModules","correct":"import { loadModules } from 'awilix-vite'"},{"note":"This is a named export, not a default export.","wrong":"import loadModules from 'awilix-vite'","symbol":"loadModules","correct":"import { loadModules } from 'awilix-vite'"},{"note":"awilix core does not export loadModules in browser/ESM builds. Use this plugin instead.","wrong":"import { loadModules } from 'awilix'","symbol":"loadModules","correct":"import { loadModules } from 'awilix-vite'"},{"note":"If using in browser/Vite, import from 'awilix/browser' to avoid Node-specific code.","wrong":"import { createContainer } from 'awilix'","symbol":"createContainer","correct":"import { createContainer } from 'awilix/browser'"}],"quickstart":{"code":"import { createContainer } from 'awilix/browser';\nimport { loadModules } from 'awilix-vite';\n\nconst container = createContainer();\n\n// Must use eager: true\nconst modules = import.meta.glob('./services/*.js', { eager: true });\n\nloadModules(container, modules, {\n  resolverOptions: {\n    lifetime: 'SINGLETON'\n  },\n  formatName: (name) => name\n});\n\nexport { container };","lang":"typescript","description":"Shows how to create an Awilix container, use import.meta.glob with eager=true, and load modules with lifecycle options."},"warnings":[{"fix":"Use { eager: true } in import.meta.glob call.","message":"import.meta.glob with eager=true is required for loadModules to work. Without eager, loaded modules are lazy imports and may not register correctly.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use a hardcoded glob pattern, not a variable.","message":"loadModules uses Vite's static analysis; dynamic glob patterns (e.g., variable paths) are not supported. The pattern must be a string literal.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Import createContainer and other Awilix primitives from 'awilix/browser'.","message":"Importing from 'awilix' (not '/browser') may cause runtime errors in browser environments due to Node dependencies (e.g., fs).","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Provide a formatName function that matches your naming convention.","message":"The formatName option receives the filename without extension; if your module files are named kebab-case, the default camelCase conversion may mangle names.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"npm install awilix-vite and ensure import is from 'awilix-vite' (not 'awilix').","cause":"Missing installation or incorrect import path.","error":"Cannot find module 'awilix-vite' or its corresponding type declarations."},{"fix":"Use import { loadModules } from 'awilix-vite'.","cause":"Default import used instead of named import.","error":"TypeError: loadModules is not a function"},{"fix":"Add '{ eager: true }' and ensure glob pattern matches at least one file.","cause":"import.meta.glob used without eager: true, or the pattern didn't match any files.","error":"Error: loadModules expects a globResult from import.meta.glob, received undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}