Skip to content

Commit d3b763d

Browse files
committed
Merge branch 'main' into v3/misc-cli-improvements
2 parents 356b3fc + 77ad412 commit d3b763d

File tree

9 files changed

+123
-17
lines changed

9 files changed

+123
-17
lines changed

.changeset/six-rats-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Improved ESM module require error detection logic

packages/cli-v3/src/commands/dev.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ function useDev({
658658
backgroundWorker
659659
);
660660
} catch (e) {
661+
logger.debug("Error starting background worker", {
662+
error: e,
663+
});
664+
661665
if (e instanceof TaskMetadataParseError) {
662666
logTaskMetadataParseError(e.zodIssues, e.tasks);
663667
return;

packages/cli-v3/src/utilities/deployErrors.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,10 @@ export function parseBuildErrorStack(error: unknown): BuildError | undefined {
2727

2828
if (errorIsErrorLike(error)) {
2929
if (typeof error.stack === "string") {
30-
const isErrRequireEsm = error.stack.includes("ERR_REQUIRE_ESM");
31-
32-
let moduleName = null;
33-
34-
if (isErrRequireEsm) {
35-
// Regular expression to match the module path
36-
const moduleRegex = /node_modules\/(@[^\/]+\/[^\/]+|[^\/]+)\/[^\/]+\s/;
37-
const match = moduleRegex.exec(error.stack);
38-
if (match) {
39-
moduleName = match[1] as string; // Capture the module name
30+
if (error.stack.includes("ERR_REQUIRE_ESM")) {
31+
const moduleName = getPackageNameFromEsmRequireError(error.stack);
4032

33+
if (moduleName) {
4134
return {
4235
type: "esm-require-error",
4336
moduleName,
@@ -50,6 +43,38 @@ export function parseBuildErrorStack(error: unknown): BuildError | undefined {
5043
}
5144
}
5245

46+
function getPackageNameFromEsmRequireError(stack: string): string | undefined {
47+
const pathRegex = /require\(\) of ES Module (.*) from/;
48+
const pathMatch = pathRegex.exec(stack);
49+
50+
if (!pathMatch) {
51+
return;
52+
}
53+
54+
const filePath = pathMatch[1];
55+
56+
if (!filePath) {
57+
return;
58+
}
59+
60+
const lastPart = filePath.split("node_modules/").pop();
61+
62+
if (!lastPart) {
63+
return;
64+
}
65+
66+
// regular expression to match the package name
67+
const moduleRegex = /(@[^\/]+\/[^\/]+|[^\/]+)/;
68+
69+
const match = moduleRegex.exec(lastPart);
70+
71+
if (!match) {
72+
return;
73+
}
74+
75+
return match[1];
76+
}
77+
5378
export function logESMRequireError(parsedError: ESMRequireError, resolvedConfig: ReadConfigResult) {
5479
logger.log(
5580
`\n${chalkError("X Error:")} The ${chalkPurple(

pnpm-lock.yaml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

references/v3-catalog/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@react-email/components": "^0.0.17",
1818
"@react-email/render": "^0.0.7",
1919
"@sindresorhus/slugify": "^2.2.1",
20+
"@t3-oss/env-nextjs": "^0.10.1",
2021
"@traceloop/instrumentation-openai": "^0.3.9",
2122
"@trigger.dev/core": "workspace:^3.0.0-beta.0",
2223
"@trigger.dev/sdk": "workspace:^3.0.0-beta.0",
@@ -31,7 +32,8 @@
3132
"server-only": "^0.0.1",
3233
"stripe": "^12.14.0",
3334
"typeorm": "^0.3.20",
34-
"yt-dlp-wrap": "^2.3.12"
35+
"yt-dlp-wrap": "^2.3.12",
36+
"zod": "3.22.3"
3537
},
3638
"devDependencies": {
3739
"@opentelemetry/api": "^1.8.0",
@@ -52,11 +54,11 @@
5254
"@trigger.dev/tsconfig": "workspace:*",
5355
"@types/node": "20.4.2",
5456
"@types/react": "^18.3.1",
57+
"esbuild": "^0.19.11",
5558
"trigger.dev": "workspace:*",
5659
"ts-node": "^10.9.2",
5760
"tsconfig-paths": "^4.2.0",
58-
"typescript": "^5.3.0",
59-
"esbuild": "^0.19.11",
60-
"tsup": "^8.0.1"
61+
"tsup": "^8.0.1",
62+
"typescript": "^5.3.0"
6163
}
6264
}

references/v3-catalog/src/env.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createEnv } from "@t3-oss/env-nextjs";
2+
import { z } from "zod";
3+
4+
export const env = createEnv({
5+
/*
6+
* Serverside Environment variables, not available on the client.
7+
* Will throw if you access these variables on the client.
8+
*/
9+
server: {
10+
TRIGGER_SECRET_KEY: z.string(),
11+
OPENAI_API_KEY: z.string().min(1),
12+
},
13+
/*
14+
* Environment variables available on the client (and server).
15+
*
16+
* 💡 You'll get type errors if these are not prefixed with NEXT_PUBLIC_.
17+
*/
18+
client: {
19+
NEXT_PUBLIC_TEST: z.string().min(1).optional(),
20+
},
21+
/*
22+
* Due to how Next.js bundles environment variables on Edge and Client,
23+
* we need to manually destructure them to make sure all are included in bundle.
24+
*
25+
* 💡 You'll get type errors if not all variables from `server` & `client` are included here.
26+
*/
27+
runtimeEnv: {
28+
TRIGGER_SECRET_KEY: process.env.TRIGGER_SECRET_KEY,
29+
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
30+
NEXT_PUBLIC_TEST: process.env.NEXT_PUBLIC_TEST,
31+
},
32+
});

references/v3-catalog/src/trigger/concurrency.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { logger, task, wait } from "@trigger.dev/sdk/v3";
22

3+
import { env } from "../env";
4+
35
export const oneAtATime = task({
46
id: "on-at-a-time",
57
queue: {
68
concurrencyLimit: 1,
79
},
810
run: async (payload: { message: string }) => {
9-
logger.info("One at a time task payload", { payload });
11+
logger.info("One at a time task payload", { payload, env });
1012

1113
await wait.for({ seconds: 10 });
1214

references/v3-catalog/trigger.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const config: TriggerConfig = {
4848
enableConsoleLogging: false,
4949
additionalPackages: ["[email protected]", "[email protected]"],
5050
additionalFiles: ["./wrangler/wrangler.toml"],
51-
dependenciesToBundle: [/@sindresorhus/, "escape-string-regexp"],
51+
dependenciesToBundle: [/@sindresorhus/, "escape-string-regexp", /@t3-oss/],
5252
instrumentations: [new OpenAIInstrumentation()],
5353
logLevel: "info",
5454
onStart: async (payload, { ctx }) => {

references/v3-catalog/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"@trigger.dev/sdk/v3/*": ["../../packages/trigger-sdk/src/v3/*"]
1414
},
1515
"emitDecoratorMetadata": true,
16-
"experimentalDecorators": true
16+
"experimentalDecorators": true,
17+
"allowJs": true,
18+
"moduleResolution": "Bundler",
19+
"module": "ES2015"
1720
}
1821
}

0 commit comments

Comments
 (0)