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)

Most upvoted comments

Thank you for your dedication 😊

Fellas, please try awilix@12.0.2-alpha.0

.nvmrc is from node-version-manager, kind of like venv for Python

so, does that mean that we are unable to use this unless we update to node v22?

Yes, unless Awilix fully goes the Module way and drops CommonJS (AFAIK)

@DDuran19 I’ve added a .nvmrc file containing v22.8.0, and CF build shows this:

16:07:30.156 | Success: Dependencies restored from build cache.
-- | --
16:07:30.257 | Detected the following tools from environment: nodejs@22.8.0, npm@9.6.7
16:07:30.258 | Installing nodejs 22.8.0
16:07:31.122 | Trying to update node-build... ok

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.

image

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.