Skip to content

Commit

Permalink
fix (remix-serve): fallback to default path if source maps aren't ava…
Browse files Browse the repository at this point in the history
…ilable when building stack trace (#8446)

Co-authored-by: Matt Brophy <[email protected]>
  • Loading branch information
VHall1 and brophdawg11 authored Jan 9, 2024
1 parent 4f0a730 commit 089f418
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-books-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/serve": patch
---

Don't try to load sourcemaps if they don't exist on disk
14 changes: 8 additions & 6 deletions packages/remix-serve/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ process.env.NODE_ENV = process.env.NODE_ENV ?? "production";

sourceMapSupport.install({
retrieveSourceMap: function (source) {
// get source file with the `file://` prefix
let match = source.match(/^file:\/\/(.*)$/);
let match = source.startsWith("file://");
if (match) {
let filePath = url.fileURLToPath(source);
return {
url: source,
map: fs.readFileSync(`${filePath}.map`, "utf8"),
};
let sourceMapPath = `${filePath}.map`;
if (fs.existsSync(sourceMapPath)) {
return {
url: source,
map: fs.readFileSync(sourceMapPath, "utf8"),
};
}
}
return null;
},
Expand Down
14 changes: 8 additions & 6 deletions templates/express/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import sourceMapSupport from "source-map-support";

sourceMapSupport.install({
retrieveSourceMap: function (source) {
// get source file with the `file://` prefix
const match = source.match(/^file:\/\/(.*)$/);
const match = source.startsWith("file://");
if (match) {
const filePath = url.fileURLToPath(source);
return {
url: source,
map: fs.readFileSync(`${filePath}.map`, "utf8"),
};
const sourceMapPath = `${filePath}.map`;
if (fs.existsSync(sourceMapPath)) {
return {
url: source,
map: fs.readFileSync(sourceMapPath, "utf8"),
};
}
}
return null;
},
Expand Down

0 comments on commit 089f418

Please sign in to comment.