awilix: Cloudflare build fails due to Node APIs
Importing only createContainer from awilix causes the build to crash.
It seems that listModules (which relies on fast-glob) is being implicitly included, even when not used which is a problem as Cloudflare Pages and Workers have limited support for Node.js APIs (with nodejs_compat).
Workaround : import from the browser build and manually assign the types
import type { asFunction as asFunctionTyped, createContainer as createContainerTyped } from 'awilix'
// @ts-expect-error
import { asFunction as _asFunction, createContainer as _createContainer } from 'awilix/lib/awilix.browser.js'
const asFunction: typeof asFunctionTyped = _asFunction
const createContainer: typeof createContainerTyped = _createContainer
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 56 (28 by maintainers)
Thank you for your dedication 😊
Fellas, please try
awilix@12.0.2-alpha.0.nvmrcis from node-version-manager, kind of likevenvfor PythonYes, unless Awilix fully goes the Module way and drops CommonJS (AFAIK)
@DDuran19 I’ve added a
.nvmrcfile containingv22.8.0, and CF build shows this:So it uses node v22 in my case.
Its definitely possible, but have duplicate files bloats the package size. I suppose renaming it would be the best option, I was just hoping adding the proper key would be sufficient.
It seems like Option 1 is backwards-compatible and solves the immediate problem, so I think we should go for that for the time being.