I ran into this issue too - `Error:

I ran into this issue too - Error: require() is not yet implemented in Workers A simple worker [with not imports] works fine. But, when inngest is imported, it fails
3 Replies
Prince
PrinceOP7mo ago
vitest.config.ts
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";

export default defineWorkersConfig({
test: {
name: "example-worker",
server: {
deps: {
inline: [
// /@hono\/zod-validtor/,
// /@hono\/zod-openapi/,
// /zod-to-openapi/,
// Without this, there is an error
// TypeError: Cannot read properties of undefined (reading 'bold')
// in `monorepo/node_modules/.pnpm/[email protected][email protected]/node_modules/inngest/index.js?mf_vitest_no_cjs_esm_shim:6:17`
/inngest/,
],
},
},
poolOptions: {
workers: {
main: "src/index.ts",
wrangler: { configPath: "./wrangler.json" },
miniflare: {
compatibilityFlags: ["nodejs_compat"],
},
},
},
},
});
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";

export default defineWorkersConfig({
test: {
name: "example-worker",
server: {
deps: {
inline: [
// /@hono\/zod-validtor/,
// /@hono\/zod-openapi/,
// /zod-to-openapi/,
// Without this, there is an error
// TypeError: Cannot read properties of undefined (reading 'bold')
// in `monorepo/node_modules/.pnpm/[email protected][email protected]/node_modules/inngest/index.js?mf_vitest_no_cjs_esm_shim:6:17`
/inngest/,
],
},
},
poolOptions: {
workers: {
main: "src/index.ts",
wrangler: { configPath: "./wrangler.json" },
miniflare: {
compatibilityFlags: ["nodejs_compat"],
},
},
},
},
});
Prince
PrinceOP7mo ago
src/index.ts
import { Hono } from "hono";

type Bindings = {};

const app = new Hono<{ Bindings: Bindings }>();

app.get("/test", (c) => {
return c.json({ success: true });
});

app.get("/inngest-test", async (c) => {
// The same error occurs when imported at the top of the file
// But, this way (ie, with a dynamic import), I can show `/test` works fine
const { Inngest } = await import("inngest");
const inngest = new Inngest({ id: "foo" });
return c.json({ success: true, inngestClientId: inngest.id });
});

export default app;
import { Hono } from "hono";

type Bindings = {};

const app = new Hono<{ Bindings: Bindings }>();

app.get("/test", (c) => {
return c.json({ success: true });
});

app.get("/inngest-test", async (c) => {
// The same error occurs when imported at the top of the file
// But, this way (ie, with a dynamic import), I can show `/test` works fine
const { Inngest } = await import("inngest");
const inngest = new Inngest({ id: "foo" });
return c.json({ success: true, inngestClientId: inngest.id });
});

export default app;
src/index.test.ts
import {
createExecutionContext,
env,
waitOnExecutionContext,
} from "cloudflare:test";
import { describe, expect, it } from "vitest";

import worker from ".";

describe("Worker", () => {
it("should return 200 response", async () => {
const url = new URL("/test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});

it("should return 200 response, when inngest is imported", async () => {
const url = new URL("/inngest-test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});
});
import {
createExecutionContext,
env,
waitOnExecutionContext,
} from "cloudflare:test";
import { describe, expect, it } from "vitest";

import worker from ".";

describe("Worker", () => {
it("should return 200 response", async () => {
const url = new URL("/test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});

it("should return 200 response, when inngest is imported", async () => {
const url = new URL("/inngest-test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});
});
richburdon
richburdon5mo ago
did you ever resolved this? i'm having the same issue.
Want results from more Discord servers?
Add your server