Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong source path resolved from the stack frame to not expose internal code #23203

Merged
merged 4 commits into from
Mar 20, 2021

Conversation

shuding
Copy link
Member

@shuding shuding commented Mar 18, 2021

Currently Next.js exposes internal code in the error overlay if certain errors were created from the user code. Some examples were attached in #20776.

We can clearly see that the path is wrong (../next-server), it should be ./node_modules/next/dist/next-server:

CleanShot 2021-03-19 at 01 33 04

The root cause is the __nextjs_original-stack-frame middleware resolves the file path with the following code:

path.resolve(
  rootDirectory,
  getSourcePath(sourcePosition.source)
)

where rootDirectory is the app root, but sourcePosition.source comes from the module path, which is relative to the path of the next binary, not the app root.

That explains why we see ../next-server from the error above, because it's relative to ./node_modules/next/bin/next.

Because of that, the resolved result will never have node_modules in its path and it won't be filtered by the error overlay in the UI. Here's a screenshot of the frame object in the UI:

CleanShot 2021-03-18 at 23 01 29@2x

And the filter we use to determine if a frame is expanded or not only depends on body.originalStackFrame:

expanded: !Boolean(
  body.originalStackFrame?.file?.includes('node_modules') ?? true
)

So this PR also adds source.file check to ensure they will be ignored (not necessary because we fixed the path resolving).

Fixes #20776.

Verified

This commit was signed with the committer’s verified signature.
nbbeeken Neal Beeken
@shuding shuding requested a review from timneutkens March 18, 2021 17:41

Verified

This commit was signed with the committer’s verified signature.
nbbeeken Neal Beeken
@ijjk
Copy link
Member

ijjk commented Mar 18, 2021

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 9.9s 9.6s -233ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
/ failed reqs 0 0
/ total time (seconds) 1.716 1.775 ⚠️ +0.06
/ avg req/sec 1457.21 1408.37 ⚠️ -48.84
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.05 1.056 ⚠️ +0.01
/error-in-render avg req/sec 2380.73 2367.75 ⚠️ -12.98
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.14 kB 7.14 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-e6cee42..49eb.js gzip 1.64 kB 1.64 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.64 kB 8.64 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 346 B 346 B
Overall change 346 B 346 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
index.html gzip 612 B 612 B
link.html gzip 621 B 621 B
withRouter.html gzip 607 B 607 B
Overall change 1.84 kB 1.84 kB

Serverless Mode
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 12.2s 12s -255ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.14 kB 7.14 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-e6cee42..49eb.js gzip 1.64 kB 1.64 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.64 kB 8.64 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 346 B 346 B
Overall change 346 B 346 B
Serverless bundles
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_error.js 1.02 MB 1.02 MB
404.html 2.67 kB 2.67 kB
500.html 2.65 kB 2.65 kB
amp.amp.html 10.6 kB 10.6 kB
amp.html 1.86 kB 1.86 kB
hooks.html 1.92 kB 1.92 kB
index.js 1.02 MB 1.02 MB
link.js 1.08 MB 1.08 MB
routerDirect.js 1.07 MB 1.07 MB
withRouter.js 1.07 MB 1.07 MB
Overall change 5.27 MB 5.27 MB

Webpack 5 Mode (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 12.4s 12.1s -271ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
/ failed reqs 0 0
/ total time (seconds) 1.761 1.83 ⚠️ +0.07
/ avg req/sec 1419.74 1366.19 ⚠️ -53.55
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.153 1.144 -0.01
/error-in-render avg req/sec 2167.79 2185.74 +17.95
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
597-12fee761..569d.js gzip 13.3 kB 13.3 kB
framework.HASH.js gzip 39.3 kB 39.3 kB
main-HASH.js gzip 7.1 kB 7.1 kB
webpack-HASH.js gzip 993 B 993 B
Overall change 60.7 kB 60.7 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-d0eb668..79ef.js gzip 1.28 kB 1.28 kB
_error-d12ff..6063.js gzip 3.4 kB 3.4 kB
amp-127483e4..9cd8.js gzip 560 B 560 B
hooks-75994b..62d3.js gzip 924 B 924 B
index-ac1ee6..819e.js gzip 243 B 243 B
link-1cd4709..71e5.js gzip 1.65 kB 1.65 kB
routerDirect..4d90.js gzip 333 B 333 B
withRouter-0..60b0.js gzip 329 B 329 B
Overall change 8.72 kB 8.72 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 324 B 324 B
Overall change 324 B 324 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
index.html gzip 588 B 588 B
link.html gzip 595 B 595 B
withRouter.html gzip 581 B 581 B
Overall change 1.76 kB 1.76 kB

Diffs

Diff for index.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/",
         "query": {},
-        "buildId": "M-1IbtIU3WTd1TvFOf0jf",
+        "buildId": "1GlOMCQrhehbxXpZwGz2c",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/M-1IbtIU3WTd1TvFOf0jf/_buildManifest.js"
+      src="/_next/static/1GlOMCQrhehbxXpZwGz2c/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/M-1IbtIU3WTd1TvFOf0jf/_ssgManifest.js"
+      src="/_next/static/1GlOMCQrhehbxXpZwGz2c/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for link.html
@@ -48,7 +48,7 @@
         "props": { "pageProps": {} },
         "page": "/link",
         "query": {},
-        "buildId": "M-1IbtIU3WTd1TvFOf0jf",
+        "buildId": "1GlOMCQrhehbxXpZwGz2c",
         "isFallback": false,
         "gip": true
       }
@@ -82,11 +82,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/M-1IbtIU3WTd1TvFOf0jf/_buildManifest.js"
+      src="/_next/static/1GlOMCQrhehbxXpZwGz2c/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/M-1IbtIU3WTd1TvFOf0jf/_ssgManifest.js"
+      src="/_next/static/1GlOMCQrhehbxXpZwGz2c/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for withRouter.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/withRouter",
         "query": {},
-        "buildId": "M-1IbtIU3WTd1TvFOf0jf",
+        "buildId": "1GlOMCQrhehbxXpZwGz2c",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/M-1IbtIU3WTd1TvFOf0jf/_buildManifest.js"
+      src="/_next/static/1GlOMCQrhehbxXpZwGz2c/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/M-1IbtIU3WTd1TvFOf0jf/_ssgManifest.js"
+      src="/_next/static/1GlOMCQrhehbxXpZwGz2c/_ssgManifest.js"
       async=""
     ></script>
   </body>
Commit: e029c68

@shuding shuding marked this pull request as ready for review March 18, 2021 19:00
Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just needs a test added in test/acceptance 👍

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@ijjk
Copy link
Member

ijjk commented Mar 19, 2021

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 12.1s 12.2s ⚠️ +101ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
/ failed reqs 0 0
/ total time (seconds) 2.267 2.287 ⚠️ +0.02
/ avg req/sec 1102.83 1093.16 ⚠️ -9.67
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.539 1.542 0
/error-in-render avg req/sec 1624.22 1621.64 ⚠️ -2.58
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.14 kB 7.14 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-e6cee42..49eb.js gzip 1.64 kB 1.64 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.64 kB 8.64 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 346 B 346 B
Overall change 346 B 346 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
index.html gzip 613 B 613 B
link.html gzip 622 B 622 B
withRouter.html gzip 609 B 609 B
Overall change 1.84 kB 1.84 kB

Serverless Mode
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 14s 14.1s ⚠️ +40ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.14 kB 7.14 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-e6cee42..49eb.js gzip 1.64 kB 1.64 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.64 kB 8.64 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 346 B 346 B
Overall change 346 B 346 B
Serverless bundles
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_error.js 1.02 MB 1.02 MB
404.html 2.67 kB 2.67 kB
500.html 2.65 kB 2.65 kB
amp.amp.html 10.6 kB 10.6 kB
amp.html 1.86 kB 1.86 kB
hooks.html 1.92 kB 1.92 kB
index.js 1.02 MB 1.02 MB
link.js 1.08 MB 1.08 MB
routerDirect.js 1.07 MB 1.07 MB
withRouter.js 1.07 MB 1.07 MB
Overall change 5.27 MB 5.27 MB

Webpack 5 Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 14.2s 14.6s ⚠️ +423ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Page Load Tests Overall increase ✓
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
/ failed reqs 0 0
/ total time (seconds) 2.239 2.239
/ avg req/sec 1116.64 1116.62 ⚠️ -0.02
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.473 1.432 -0.04
/error-in-render avg req/sec 1697.5 1745.96 +48.46
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
597-12fee761..569d.js gzip 13.3 kB 13.3 kB
framework.HASH.js gzip 39.3 kB 39.3 kB
main-HASH.js gzip 7.1 kB 7.1 kB
webpack-HASH.js gzip 993 B 993 B
Overall change 60.7 kB 60.7 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-d0eb668..79ef.js gzip 1.28 kB 1.28 kB
_error-d12ff..6063.js gzip 3.4 kB 3.4 kB
amp-127483e4..9cd8.js gzip 560 B 560 B
hooks-75994b..62d3.js gzip 924 B 924 B
index-ac1ee6..819e.js gzip 243 B 243 B
link-1cd4709..71e5.js gzip 1.65 kB 1.65 kB
routerDirect..4d90.js gzip 333 B 333 B
withRouter-0..60b0.js gzip 329 B 329 B
Overall change 8.72 kB 8.72 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 324 B 324 B
Overall change 324 B 324 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
index.html gzip 586 B 586 B
link.html gzip 593 B 593 B
withRouter.html gzip 580 B 580 B
Overall change 1.76 kB 1.76 kB

Diffs

Diff for index.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/",
         "query": {},
-        "buildId": "61pxbaC_mdk6L4e-L-S04",
+        "buildId": "eIMoc3BXVtrIOcUGPkCm4",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/61pxbaC_mdk6L4e-L-S04/_buildManifest.js"
+      src="/_next/static/eIMoc3BXVtrIOcUGPkCm4/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/61pxbaC_mdk6L4e-L-S04/_ssgManifest.js"
+      src="/_next/static/eIMoc3BXVtrIOcUGPkCm4/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for link.html
@@ -48,7 +48,7 @@
         "props": { "pageProps": {} },
         "page": "/link",
         "query": {},
-        "buildId": "61pxbaC_mdk6L4e-L-S04",
+        "buildId": "eIMoc3BXVtrIOcUGPkCm4",
         "isFallback": false,
         "gip": true
       }
@@ -82,11 +82,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/61pxbaC_mdk6L4e-L-S04/_buildManifest.js"
+      src="/_next/static/eIMoc3BXVtrIOcUGPkCm4/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/61pxbaC_mdk6L4e-L-S04/_ssgManifest.js"
+      src="/_next/static/eIMoc3BXVtrIOcUGPkCm4/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for withRouter.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/withRouter",
         "query": {},
-        "buildId": "61pxbaC_mdk6L4e-L-S04",
+        "buildId": "eIMoc3BXVtrIOcUGPkCm4",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/61pxbaC_mdk6L4e-L-S04/_buildManifest.js"
+      src="/_next/static/eIMoc3BXVtrIOcUGPkCm4/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/61pxbaC_mdk6L4e-L-S04/_ssgManifest.js"
+      src="/_next/static/eIMoc3BXVtrIOcUGPkCm4/_ssgManifest.js"
       async=""
     ></script>
   </body>
Commit: ae1cd25

@shuding shuding requested a review from timneutkens March 19, 2021 17:09
@ijjk
Copy link
Member

ijjk commented Mar 20, 2021

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 12.1s 12.3s ⚠️ +106ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Page Load Tests Overall increase ✓
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
/ failed reqs 0 0
/ total time (seconds) 2.215 2.177 -0.04
/ avg req/sec 1128.74 1148.29 +19.55
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.52 1.532 ⚠️ +0.01
/error-in-render avg req/sec 1644.79 1631.47 ⚠️ -13.32
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.14 kB 7.14 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-e6cee42..49eb.js gzip 1.64 kB 1.64 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.64 kB 8.64 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 346 B 346 B
Overall change 346 B 346 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
index.html gzip 613 B 613 B
link.html gzip 622 B 622 B
withRouter.html gzip 609 B 609 B
Overall change 1.84 kB 1.84 kB

Serverless Mode
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 13.8s 13.6s -267ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.14 kB 7.14 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-e6cee42..49eb.js gzip 1.64 kB 1.64 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.64 kB 8.64 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 346 B 346 B
Overall change 346 B 346 B
Serverless bundles
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_error.js 1.02 MB 1.02 MB
404.html 2.67 kB 2.67 kB
500.html 2.65 kB 2.65 kB
amp.amp.html 10.6 kB 10.6 kB
amp.html 1.86 kB 1.86 kB
hooks.html 1.92 kB 1.92 kB
index.js 1.02 MB 1.02 MB
link.js 1.08 MB 1.08 MB
routerDirect.js 1.07 MB 1.07 MB
withRouter.js 1.07 MB 1.07 MB
Overall change 5.27 MB 5.27 MB

Webpack 5 Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
buildDuration 13.7s 14.2s ⚠️ +469ms
nodeModulesSize 43.6 MB 43.6 MB ⚠️ +336 B
Page Load Tests Overall increase ✓
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
/ failed reqs 0 0
/ total time (seconds) 2.185 2.144 -0.04
/ avg req/sec 1144.35 1165.93 +21.58
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.462 1.455 -0.01
/error-in-render avg req/sec 1710.41 1718.02 +7.61
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
597-12fee761..569d.js gzip 13.3 kB 13.3 kB
framework.HASH.js gzip 39.3 kB 39.3 kB
main-HASH.js gzip 7.1 kB 7.1 kB
webpack-HASH.js gzip 993 B 993 B
Overall change 60.7 kB 60.7 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_app-d0eb668..79ef.js gzip 1.28 kB 1.28 kB
_error-d12ff..6063.js gzip 3.4 kB 3.4 kB
amp-127483e4..9cd8.js gzip 560 B 560 B
hooks-75994b..62d3.js gzip 924 B 924 B
index-ac1ee6..819e.js gzip 243 B 243 B
link-1cd4709..71e5.js gzip 1.65 kB 1.65 kB
routerDirect..4d90.js gzip 333 B 333 B
withRouter-0..60b0.js gzip 329 B 329 B
Overall change 8.72 kB 8.72 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
_buildManifest.js gzip 324 B 324 B
Overall change 324 B 324 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-error-frame-wrong-path Change
index.html gzip 586 B 586 B
link.html gzip 593 B 593 B
withRouter.html gzip 580 B 580 B
Overall change 1.76 kB 1.76 kB

Diffs

Diff for index.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/",
         "query": {},
-        "buildId": "KdptVQ_qyzhjYaQHnfu2X",
+        "buildId": "5qSiS_O4mWDSKv9Sf6IH-",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/KdptVQ_qyzhjYaQHnfu2X/_buildManifest.js"
+      src="/_next/static/5qSiS_O4mWDSKv9Sf6IH-/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/KdptVQ_qyzhjYaQHnfu2X/_ssgManifest.js"
+      src="/_next/static/5qSiS_O4mWDSKv9Sf6IH-/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for link.html
@@ -48,7 +48,7 @@
         "props": { "pageProps": {} },
         "page": "/link",
         "query": {},
-        "buildId": "KdptVQ_qyzhjYaQHnfu2X",
+        "buildId": "5qSiS_O4mWDSKv9Sf6IH-",
         "isFallback": false,
         "gip": true
       }
@@ -82,11 +82,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/KdptVQ_qyzhjYaQHnfu2X/_buildManifest.js"
+      src="/_next/static/5qSiS_O4mWDSKv9Sf6IH-/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/KdptVQ_qyzhjYaQHnfu2X/_ssgManifest.js"
+      src="/_next/static/5qSiS_O4mWDSKv9Sf6IH-/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for withRouter.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/withRouter",
         "query": {},
-        "buildId": "KdptVQ_qyzhjYaQHnfu2X",
+        "buildId": "5qSiS_O4mWDSKv9Sf6IH-",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/KdptVQ_qyzhjYaQHnfu2X/_buildManifest.js"
+      src="/_next/static/5qSiS_O4mWDSKv9Sf6IH-/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/KdptVQ_qyzhjYaQHnfu2X/_ssgManifest.js"
+      src="/_next/static/5qSiS_O4mWDSKv9Sf6IH-/_ssgManifest.js"
       async=""
     ></script>
   </body>
Commit: 42fabd8

@kodiakhq kodiakhq bot merged commit 89ec21e into vercel:canary Mar 20, 2021
@spmsupun
Copy link

Thanks and good job :)

@shuding shuding deleted the fix-error-frame-wrong-path branch March 20, 2021 20:22
@spmsupun
Copy link

@shuding when will this be merged to the stable/production?

@timneutkens
Copy link
Member

It's in 10.1.0: https://github.com/vercel/next.js/releases/tag/v10.1.0. You'll want to upgrade to next@latest.

@spmsupun
Copy link

I have upgraded to 10.1.3 but the issue remains:
#20776 (comment)

flybayer pushed a commit to blitz-js/next.js that referenced this pull request Apr 29, 2021
…ernal code (vercel#23203)

Currently Next.js exposes internal code in the error overlay if certain errors were created from the user code. Some examples were attached in vercel#20776.

We can clearly see that the path is wrong (`../next-server`), it should be `./node_modules/next/dist/next-server`:

![CleanShot 2021-03-19 at 01 33 04](https://user-images.githubusercontent.com/3676859/111670728-1ae7e400-8853-11eb-9213-3b359798900e.png)

The root cause is the `__nextjs_original-stack-frame` middleware resolves the file path with the following code:

```js
path.resolve(
  rootDirectory,
  getSourcePath(sourcePosition.source)
)
```

where `rootDirectory` is the **app root**, but `sourcePosition.source` comes from the module path, which is relative to the path of the `next` binary, not the app root. 

That explains why we see `../next-server` from the error above, because it's relative to `./node_modules/next/bin/next`.

Because of that, the resolved result will never have `node_modules` in its path and it won't be filtered by the error overlay in the UI. Here's a screenshot of the frame object in the UI:

![CleanShot 2021-03-18 at 23 01 29@2x](https://user-images.githubusercontent.com/3676859/111670062-65b52c00-8852-11eb-9293-3a6e5b7c4b9b.png)

And the filter we use to determine if a frame is expanded or not only depends on `body.originalStackFrame`:

```js
expanded: !Boolean(
  body.originalStackFrame?.file?.includes('node_modules') ?? true
)
```

So this PR also adds `source.file` check to ensure they will be ignored (not necessary because we fixed the path resolving).

Fixes vercel#20776.
@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why does next.js offen shows the wrong line/file when there's an error?
4 participants