Dan @ InngestD
Convex Community9mo ago
17 replies
Dan @ Inngest

Help with writing Inngest http action - dynamic Node require

Hi there,
A user of our community asked about a Convex adapter for Inngest and when building it, it failed with the following error:

✘ [ERROR] Could not resolve "node:async_hooks"

    node_modules/.pnpm/inngest@3.39.2_typescript@5.8.3/node_modules/inngest/components/execution/als.js:61:98:
      61 │ ...st { AsyncLocalStorage } = await Promise.resolve().then(() => __importStar(require("node:async_hooks")));
         ╵                                                                                       ~~~~~~~~~~~~~~~~~~

  The package "node:async_hooks" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

It looks like you are using Node APIs from a file without the "use node" directive.
Split out actions using Node.js APIs like this into a new file only containing actions that uses "use node" so these actions will run in a Node.js environment.
For more information see https://docs.convex.dev/functions/runtimes#nodejs-runtime


I attempted to:
* Modify the Inngest source to add
"use node"
and it didn't work
* Add
"use node"
in my
convex/inngest.js
http action file
* Add
"node": { "externalPackages": ["inngest"] }
to my
convex.json
file

None of the above worked, but I also saw something about Convex not supporting dynamic requires or imports at all. Is there a way to work around this or perhaps detect it in the Inngest package source code so it gracefully doesn't support this functionality?

Sources:
* Inngest source code for this import - It uses import in the source, but when transpiled for npm, it uses a
require
as seen in the error above.


Thanks!
GitHub
The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript - inngest/inngest-js
inngest-js/packages/inngest/src/components/execution/als.ts at bf8a...
Was this page helpful?