Registry / web-framework / awilix-vite

awilix-vite

JSON →
library2.0.3jsnpmunverified

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.

npm install awilix-vite
INSTALL
IMPORT
SIG · AWILIX-VITE
A
awilix-vite
web-frameworkjavascriptv2.0.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

loadModules
✓ import { loadModules } from 'awilix-vite'
✗ const loadModules = require('awilix-vite')
ESM-only package; require() will fail. Use import.
loadModules
✓ import { loadModules } from 'awilix-vite'
✗ import loadModules from 'awilix-vite'
This is a named export, not a default export.
loadModules
✓ import { loadModules } from 'awilix-vite'
✗ import { loadModules } from 'awilix'
awilix core does not export loadModules in browser/ESM builds. Use this plugin instead.
createContainer
✓ import { createContainer } from 'awilix/browser'
✗ import { createContainer } from 'awilix'
If using in browser/Vite, import from 'awilix/browser' to avoid Node-specific code.

Shows how to create an Awilix container, use import.meta.glob with eager=true, and load modules with lifecycle options.

import { createContainer } from 'awilix/browser'; import { loadModules } from 'awilix-vite'; const container = createContainer(); // Must use eager: true const modules = import.meta.glob('./services/*.js', { eager: true }); loadModules(container, modules, { resolverOptions: { lifetime: 'SINGLETON' }, formatName: (name) => name }); export { container };
Debug
Known issues
breakingimport.meta.glob with eager=true is required for loadModules to work. Without eager, loaded modules are lazy imports and may not register correctly.
fix
Use { eager: true } in import.meta.glob call.
affects: >=1.0.0
gotchaloadModules uses Vite's static analysis; dynamic glob patterns (e.g., variable paths) are not supported. The pattern must be a string literal.
fix
Use a hardcoded glob pattern, not a variable.
affects: >=1.0.0
deprecatedImporting from 'awilix' (not '/browser') may cause runtime errors in browser environments due to Node dependencies (e.g., fs).
fix
Import createContainer and other Awilix primitives from 'awilix/browser'.
affects: >=2.0.0
gotchaThe formatName option receives the filename without extension; if your module files are named kebab-case, the default camelCase conversion may mangle names.
fix
Provide a formatName function that matches your naming convention.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'awilix-vite' or its corresponding type declarations.
Missing installation or incorrect import path.
fix
npm install awilix-vite and ensure import is from 'awilix-vite' (not 'awilix').
TypeError: loadModules is not a function
Default import used instead of named import.
fix
Use import { loadModules } from 'awilix-vite'.
Error: loadModules expects a globResult from import.meta.glob, received undefined
import.meta.glob used without eager: true, or the pattern didn't match any files.
fix
Add '{ eager: true }' and ensure glob pattern matches at least one file.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
awilixrequiredpeer dependency for container creation and resolver options
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources
awilix-vite — npm install awilix-vite · libregistry