spatie/sourcemaps-lookup
Fast, memory-efficient Source Map v3 lookup for PHP. Resolve JavaScript stack frames to original source file, line/column, symbol name, and enclosing scope. Optimized for the read path and high-volume error symbolicating from uploaded sourcemaps.
$map = SourceMapLookup::fromFile(public_path('js/bundle.js.map'));
$position = $map->lookup(42, 17);
booted event or middleware to automatically resolve stack traces from frontend errors (e.g., via JavaScript window.onerror).null or incorrect mappings. Mitigation:
source-map-resolve in Node.js).scopeAt() feature is heuristic-only (no native scopes field support). Useful for basic scoping but not reliable for complex cases (e.g., closures in React hooks).Where will source maps be stored?
public/js/*.map)?source_maps table)?
Impact: Affects caching strategy and error handling.How will errors be ingested?
fetch('/api/errors', { body: error }))?What’s the fallback for unresolved positions?
Will this be used for production errors only, or also dev-time debugging?
debugbar or telescope.Are there existing source map tools in the stack?
source-map in Node.js, browser DevTools.Phase 1: Proof of Concept
composer.json.resources/js/app.js.map).lookup() returns correct original positions.Phase 2: Error Integration
Error.stack or custom metadata)./api/symbolicate) to accept errors and return resolved positions.Route::post('/symbolicate', function (Request $request) {
$error = $request->json()->all();
$map = SourceMapLookup::fromFile($error['sourceMapUrl']);
$position = $map->lookup($error['line'], $error['column']);
return response()->json(['resolved' => $position]);
});
Phase 3: Caching & Scaling
SourceMapLookup instances (e.g., in Redis) to avoid reprocessing.vite.config.js or Laravel Mix).Phase 4: Scope & UI Enhancements
scopeAt() to highlight function boundaries in error displays.sourceLines() to show snippets of original code in error emails/notifications.Error in `onClick` (src/components/Button.tsx:42)
Snippet:
38 | const handleClick = () => {
39 | setCount(c => c + 1);
> 40 | analytics.track('button_clicked');
41 | };
42 | return <button onClick={handleClick}>...
devtool: 'source-map' in config.sourcemap: true.UnsupportedSourceMap. Workaround: Use a tool like source-map-resolve to flatten maps pre-processing.InvalidSourceMap/UnsupportedSourceMap. Log these for debugging.Frontend Setup
window.onerror).Backend Integration
composer.json./symbolicate endpoint or middleware.Error Pipeline
UI/UX Layer
scopeAt() and sourceLines() for context-rich debugging.composer update).InvalidSourceMap/UnsupportedSourceMap should be logged but not crash the app.sourceFileName may be relative).scopeAt() heuristics).How can I help you explore Laravel packages today?