diff --git a/bootstrap.sh b/bootstrap.sh index ba8ac5e2959..a82b2b84b71 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -346,7 +346,7 @@ function start_txes { for i in $(seq 0 $((NUM_TXES-1))); do port=$((txe_base_port + i)) kill_port $port - dump_fail "LOG_LEVEL=info TXE_PORT=$port retry 'node --no-warnings ./yarn-project/txe/dest/bin/index.js'" & + dump_fail "LOG_LEVEL=info TXE_PORT=$port retry 'node --no-warnings ./yarn-project/txe/dest/bin/index.bundle.js'" & txe_pids+="$! " done diff --git a/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts b/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts index 27618dcb67d..9d849dade05 100644 --- a/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts +++ b/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts @@ -14,7 +14,7 @@ import { EcdsaKBaseAccountContract } from './account_contract.js'; * @returns The contract artifact for the ecdsa K account contract */ export async function getEcdsaKAccountContractArtifact() { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/accounts/src/ecdsa/ecdsa_r/lazy.ts b/yarn-project/accounts/src/ecdsa/ecdsa_r/lazy.ts index 7347c400850..f6d99374a8c 100644 --- a/yarn-project/accounts/src/ecdsa/ecdsa_r/lazy.ts +++ b/yarn-project/accounts/src/ecdsa/ecdsa_r/lazy.ts @@ -14,7 +14,7 @@ import { EcdsaRBaseAccountContract } from './account_contract.js'; * @returns The contract artifact for the ecdsa K account contract */ export async function getEcdsaRAccountContractArtifact() { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/accounts/src/ecdsa/stub/lazy.ts b/yarn-project/accounts/src/ecdsa/stub/lazy.ts index ed4187817e7..880b92311ae 100644 --- a/yarn-project/accounts/src/ecdsa/stub/lazy.ts +++ b/yarn-project/accounts/src/ecdsa/stub/lazy.ts @@ -9,8 +9,11 @@ import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js * Lazily loads the ECDSA stub contract artifact (browser-compatible). */ export async function getStubEcdsaAccountContractArtifact() { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 + // Even if now supported by all major browsers, the MIME type is replaced with + // "text/javascript" + // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS const { default: json } = await import('../../../artifacts/SimulatedEcdsaAccount.json'); return loadContractArtifact(json); } diff --git a/yarn-project/accounts/src/schnorr/initializerless/lazy.ts b/yarn-project/accounts/src/schnorr/initializerless/lazy.ts index 2476b672748..ac8f1428759 100644 --- a/yarn-project/accounts/src/schnorr/initializerless/lazy.ts +++ b/yarn-project/accounts/src/schnorr/initializerless/lazy.ts @@ -20,7 +20,7 @@ import { SchnorrBaseAccountContract } from '../account_contract.js'; * @returns The contract artifact for the schnorr account contract */ export async function getSchnorrInitializerlessAccountContractArtifact() { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/accounts/src/schnorr/private_immutable/lazy.ts b/yarn-project/accounts/src/schnorr/private_immutable/lazy.ts index 077762d213a..a6105fd039d 100644 --- a/yarn-project/accounts/src/schnorr/private_immutable/lazy.ts +++ b/yarn-project/accounts/src/schnorr/private_immutable/lazy.ts @@ -19,7 +19,7 @@ import { SchnorrBaseAccountContract } from '../account_contract.js'; * @returns The contract artifact for the schnorr account contract */ export async function getSchnorrAccountContractArtifact() { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/accounts/src/schnorr/stub/lazy.ts b/yarn-project/accounts/src/schnorr/stub/lazy.ts index f7382bf6fb3..371f8c9d395 100644 --- a/yarn-project/accounts/src/schnorr/stub/lazy.ts +++ b/yarn-project/accounts/src/schnorr/stub/lazy.ts @@ -9,8 +9,11 @@ import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js * Lazily loads the Schnorr stub contract artifact (browser-compatible). */ export async function getStubSchnorrAccountContractArtifact() { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 + // Even if now supported by all major browsers, the MIME type is replaced with + // "text/javascript" + // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS const { default: json } = await import('../../../artifacts/SimulatedSchnorrAccount.json'); return loadContractArtifact(json); } diff --git a/yarn-project/protocol-contracts/src/class-registry/lazy.ts b/yarn-project/protocol-contracts/src/class-registry/lazy.ts index 17ea9781d3c..0502a9d9938 100644 --- a/yarn-project/protocol-contracts/src/class-registry/lazy.ts +++ b/yarn-project/protocol-contracts/src/class-registry/lazy.ts @@ -10,7 +10,7 @@ let protocolContractArtifact: ContractArtifact; export async function getContractClassRegistryArtifact(): Promise { if (!protocolContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/protocol-contracts/src/fee-juice/lazy.ts b/yarn-project/protocol-contracts/src/fee-juice/lazy.ts index 04651ddfb5a..3a819d07d6a 100644 --- a/yarn-project/protocol-contracts/src/fee-juice/lazy.ts +++ b/yarn-project/protocol-contracts/src/fee-juice/lazy.ts @@ -8,7 +8,7 @@ let protocolContractArtifact: ContractArtifact; export async function getFeeJuiceArtifact(): Promise { if (!protocolContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/protocol-contracts/src/instance-registry/lazy.ts b/yarn-project/protocol-contracts/src/instance-registry/lazy.ts index bb3bc7aa3cb..fc239aefc0b 100644 --- a/yarn-project/protocol-contracts/src/instance-registry/lazy.ts +++ b/yarn-project/protocol-contracts/src/instance-registry/lazy.ts @@ -11,7 +11,7 @@ let protocolContractArtifact: ContractArtifact; export async function getContractInstanceRegistryArtifact(): Promise { if (!protocolContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/standard-contracts/src/auth-registry/lazy.ts b/yarn-project/standard-contracts/src/auth-registry/lazy.ts index 21392ff81b8..35f8c9efbcd 100644 --- a/yarn-project/standard-contracts/src/auth-registry/lazy.ts +++ b/yarn-project/standard-contracts/src/auth-registry/lazy.ts @@ -14,7 +14,7 @@ let standardContractArtifact: ContractArtifact; export async function getAuthRegistryArtifact(): Promise { if (!standardContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/standard-contracts/src/handshake-registry/lazy.ts b/yarn-project/standard-contracts/src/handshake-registry/lazy.ts index 36032dc3c59..04da2f9852f 100644 --- a/yarn-project/standard-contracts/src/handshake-registry/lazy.ts +++ b/yarn-project/standard-contracts/src/handshake-registry/lazy.ts @@ -14,7 +14,7 @@ let standardContractArtifact: ContractArtifact; export async function getHandshakeRegistryArtifact(): Promise { if (!standardContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/standard-contracts/src/multi-call-entrypoint/lazy.ts b/yarn-project/standard-contracts/src/multi-call-entrypoint/lazy.ts index 6ef1e5a4507..fd97b53ff08 100644 --- a/yarn-project/standard-contracts/src/multi-call-entrypoint/lazy.ts +++ b/yarn-project/standard-contracts/src/multi-call-entrypoint/lazy.ts @@ -14,7 +14,7 @@ let standardContractArtifact: ContractArtifact; export async function getMultiCallEntrypointArtifact(): Promise { if (!standardContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/standard-contracts/src/public-checks/lazy.ts b/yarn-project/standard-contracts/src/public-checks/lazy.ts index 9ac05a467d1..f5a86933769 100644 --- a/yarn-project/standard-contracts/src/public-checks/lazy.ts +++ b/yarn-project/standard-contracts/src/public-checks/lazy.ts @@ -14,7 +14,7 @@ let standardContractArtifact: ContractArtifact; export async function getPublicChecksArtifact(): Promise { if (!standardContractArtifact) { - // Cannot assert this import as it's incompatible with bundlers like vite + // Cannot add `with { type: 'json' }` to this import as it's incompatible with bundlers like vite // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352 // Even if now supported by all major browsers, the MIME type is replaced with // "text/javascript" diff --git a/yarn-project/txe/esbuild.config.mjs b/yarn-project/txe/esbuild.config.mjs index 46be5f76588..5c1eaf23775 100644 --- a/yarn-project/txe/esbuild.config.mjs +++ b/yarn-project/txe/esbuild.config.mjs @@ -108,8 +108,12 @@ const redirects = [ ]; const entryPoints = { - // src/bin/index.ts → dest/bin/index.js (overwrites the tsc-emitted file). - 'bin/index': 'src/bin/index.ts', + // src/bin/index.ts → dest/bin/index.bundle.js. The `.bundle` suffix (like worker/server below) + // keeps the output at a path tsc never emits: a tsc-only rebuild (e.g. `yarn build` at the + // yarn-project root) must not be able to replace a bundle with unbundled output, because the + // unbundled tree reaches dynamic JSON imports that Node's ESM loader rejects + // (ERR_IMPORT_ATTRIBUTE_MISSING) — TXE only runs correctly from the bundles. + 'bin/index.bundle': 'src/bin/index.ts', // src/worker.ts → dest/worker.bundle.js (the file the pool spawns). 'worker.bundle': 'src/worker.ts', // src/rpc_server.ts → dest/server.bundle.js (the entry the parent `@aztec/aztec` diff --git a/yarn-project/txe/esbuild/plugins/size_guard.mjs b/yarn-project/txe/esbuild/plugins/size_guard.mjs index f32971432bf..b9a036f6f1b 100644 --- a/yarn-project/txe/esbuild/plugins/size_guard.mjs +++ b/yarn-project/txe/esbuild/plugins/size_guard.mjs @@ -20,7 +20,7 @@ export const sizeLimits = [ { pattern: /^dest\/[A-Z][A-Za-z]+-[A-Z0-9]+\.js$/, maxKB: 800, description: 'contract artifact chunk' }, // Tiny entry stubs that just re-export from the shared chunks. { pattern: /^dest\/(worker|server)\.bundle\.js$/, maxKB: 8, description: 'entrypoint stub' }, - { pattern: /^dest\/bin\/index\.js$/, maxKB: 8, description: 'CLI entrypoint stub' }, + { pattern: /^dest\/bin\/index\.bundle\.js$/, maxKB: 8, description: 'CLI entrypoint stub' }, ]; export const totalLimitMiB = 14.5; diff --git a/yarn-project/txe/package.json b/yarn-project/txe/package.json index dcd9deb7f1c..2549a42e09a 100644 --- a/yarn-project/txe/package.json +++ b/yarn-project/txe/package.json @@ -8,7 +8,7 @@ "import": "./dest/server.bundle.js" } }, - "bin": "./dest/bin/index.js", + "bin": "./dest/bin/index.bundle.js", "typedocOptions": { "entryPoints": [ "./src/index.ts" @@ -21,8 +21,8 @@ "build:dev": "../scripts/tsc.sh --watch", "clean": "rm -rf ./dest .tsbuildinfo", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}", - "dev": "LOG_LEVEL=\"debug; trace: simulator:state_manager; info: json-rpc:proxy\" node ./dest/bin/index.js", - "start": "node --no-warnings ./dest/bin/index.js", + "dev": "node ./esbuild.config.mjs && LOG_LEVEL=\"debug; trace: simulator:state_manager; info: json-rpc:proxy\" node ./dest/bin/index.bundle.js", + "start": "node ./esbuild.config.mjs && node --no-warnings ./dest/bin/index.bundle.js", "start:oracle-test-resolver": "node --no-warnings ./dest/bin/oracle_test_server.js", "check_txe_oracle_version": "node ./dest/bin/check_txe_oracle_version.js" }, @@ -100,7 +100,7 @@ "typescript": "^5.3.3" }, "files": [ - "dest/bin/index.js", + "dest/bin/index.bundle.js", "dest/worker.bundle.js", "dest/server.bundle.js", "dest/chunk-*.js", diff --git a/yarn-project/txe/src/dispatcher_pool.ts b/yarn-project/txe/src/dispatcher_pool.ts index bac1a07e9c7..e40d7491d7a 100644 --- a/yarn-project/txe/src/dispatcher_pool.ts +++ b/yarn-project/txe/src/dispatcher_pool.ts @@ -50,9 +50,9 @@ export async function buildSharedContractStore(): Promise<{ dataDir: string; sch /** * Resolves `worker.bundle.js` whether this code is running unbundled (next to dispatcher_pool.js - * inside `dest/`) or bundled into `dest/bin/index.js` (one directory deeper). `import.meta.url` - * refers to whichever module the calling code actually lives in; we try both relative locations - * and use whichever exists. + * inside `dest/`) or bundled into `dest/bin/index.bundle.js` (one directory deeper). + * `import.meta.url` refers to whichever module the calling code actually lives in; we try both + * relative locations and use whichever exists. */ // worker.bundle.js is esbuild's bundling of src/worker.ts (see esbuild.config.mjs). // @dependency ./worker.ts