Skip to content

fix: replace illegal await-in-constructor with static crypto import (Web3 Factory broken)#240

Open
0xAxiom wants to merge 1 commit intomainfrom
fix/web3-pipeline-async-constructor
Open

fix: replace illegal await-in-constructor with static crypto import (Web3 Factory broken)#240
0xAxiom wants to merge 1 commit intomainfrom
fix/web3-pipeline-async-constructor

Conversation

@0xAxiom
Copy link
Copy Markdown
Owner

@0xAxiom 0xAxiom commented Apr 30, 2026

What

Fix a SyntaxError that prevents the Web3 Factory (web3 idea <IDEA>) from starting.

Root Cause

dapp-factory/pipeline/web3_pipeline.ts uses await import('crypto') inside the Web3Pipeline class constructor:

// ❌ Broken — constructors are synchronous, await is illegal here
constructor(config: Web3PipelineConfig) {
  ...
  const crypto = await import('crypto');   // SyntaxError at runtime
  const ideaHash = crypto.createHash('md5')...

At runtime Node.js throws:

SyntaxError: Unexpected reserved word

This crashes the process before any pipeline stage runs.

Why it wasn't caught by TypeScript: dapp-factory/tsconfig.json excludes pipeline/** from compilation, so the compiler never saw this file.

Fix

Replace the illegal dynamic import with a static import at the top of the file — consistent with prompt_enforcer.ts, which already uses import * as crypto from 'crypto':

// ✅ Fixed
import * as crypto from 'crypto';
...
constructor(config: Web3PipelineConfig) {
  ...
  const ideaHash = crypto.createHash('md5')...

No behaviour change. crypto is a Node.js built-in; static import is equivalent and synchronous.

Tested

  • Manually verified the constructor no longer throws
  • npm test — 252/252 tests pass ✅

The Web3Pipeline constructor used 'await import("crypto")' which
throws SyntaxError: Unexpected reserved word at runtime because
constructors are synchronous and cannot use await. This broke the
entire Web3 Factory pipeline on any invocation.

Fix: add 'import * as crypto from "crypto"' at the top of the file
(matching the pattern already used in prompt_enforcer.ts) and remove
the dynamic import. No behaviour change — crypto is a built-in module.
@0xAxiom 0xAxiom requested a review from MeltedMindz as a code owner April 30, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant