Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/builders/src/apply-swc-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ export async function applySwcTransform(
},
},
},
// TODO: investigate proper source map support as they
// won't even be used in Node.js by default unless we
// intercept errors and apply them ourselves
sourceMaps: false,
// node_modules have invalid source maps often so ignore there
// but enable for first party code
sourceMaps: filename.includes('node_modules') ? false : 'inline',
minify: false,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function hasStepSourceMaps(): boolean {
// TODO: we need to fix this
const appName = process.env.APP_NAME as string;
if (['nextjs-webpack', 'nextjs-turbopack'].includes(appName)) {
return false;
return true;
}

// Vercel builds have proper source maps for all other frameworks, EXCEPT sveltekit
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { types } from 'node:util';
import { inspect, types } from 'node:util';

export function getErrorName(v: unknown): string {
if (types.isNativeError(v)) {
Expand All @@ -9,7 +9,9 @@ export function getErrorName(v: unknown): string {

export function getErrorStack(v: unknown): string {
if (types.isNativeError(v)) {
return v.stack ?? '';
// Use util.inspect to get the formatted error with source maps applied.
// Accessing err.stack directly returns the raw stack without source map resolution.
return inspect(v);
}
return '';
}
22 changes: 15 additions & 7 deletions packages/next/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import { transform } from '@swc/core';

// This loader applies the "use workflow"/"use step"
// client transformation
export default async function workflowLoader(
export default function workflowLoader(
this: {
resourcePath: string;
async: () => (err: Error | null, content?: string, sourceMap?: any) => void;
},
source: string | Buffer,
sourceMap: any
): Promise<string> {
) {
const callback = this.async();
const filename = this.resourcePath;
const normalizedSource = source.toString();

// only apply the transform if file needs it
if (!normalizedSource.match(/(use step|use workflow)/)) {
return normalizedSource;
callback(null, normalizedSource, sourceMap);
return;
}

const isTypeScript =
Expand Down Expand Up @@ -64,7 +67,7 @@ export default async function workflowLoader(
}

// Transform with SWC
const result = await transform(normalizedSource, {
transform(normalizedSource, {
filename: relativeFilename,
jsc: {
parser: {
Expand Down Expand Up @@ -94,7 +97,12 @@ export default async function workflowLoader(
inputSourceMap: sourceMap,
sourceMaps: true,
inlineSourcesContent: true,
});

return result.code;
}).then(
(result) => {
callback(null, result.code);
},
(err) => {
callback(err);
}
);
}
4 changes: 2 additions & 2 deletions packages/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"inlineSources": false,
"sourceMap": false,
"inlineSourceMap": true,
"isolatedModules": true,
"moduleResolution": "node16",
"noUnusedLocals": true,
Expand Down
3 changes: 3 additions & 0 deletions workbench/nextjs-turbopack/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { withWorkflow } from 'workflow/next';
const nextConfig: NextConfig = {
/* config options here */
serverExternalPackages: ['@node-rs/xxhash'],
experimental: {
serverSourceMaps: true,
},
};

// export default nextConfig;
Expand Down
2 changes: 1 addition & 1 deletion workbench/nextjs-webpack/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const nextConfig: NextConfig = {
/* config options here */
// for easier debugging
experimental: {
serverMinification: false,
serverSourceMaps: true,
},
serverExternalPackages: ['@node-rs/xxhash'],
};
Expand Down
Loading