Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 63942db

Browse files
GatsbyJS Botpieh
GatsbyJS Bot
andauthoredMay 11, 2021
fix(gatsby): fix proxy creation on read-only properties (#31346) (#31364)
(cherry picked from commit c210f1d) Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const fs = require(`../fs`)
2+
3+
describe(`tracking fs`, () => {
4+
it(`doesn't crash on accessing fs.constants`, () => {
5+
expect(() => fs.constants).not.toThrow()
6+
})
7+
})

‎packages/gatsby/cache-dir/ssr-builtin-trackers/tracking-unsafe-module-wrapper.js

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ function createProxyHandler(prefix, options) {
1111
return value
1212
}
1313

14+
const fieldDescriptor = Object.getOwnPropertyDescriptor(target, key)
15+
if (fieldDescriptor && !fieldDescriptor.writable) {
16+
// this is to prevent errors like:
17+
// ```
18+
// TypeError: 'get' on proxy: property 'constants' is a read - only and
19+
// non - configurable data property on the proxy target but the proxy
20+
// did not return its actual value
21+
// (expected '[object Object]' but got '[object Object]')
22+
// ```
23+
return value
24+
}
25+
1426
if (typeof value === `function`) {
1527
return function wrapper(...args) {
1628
const myErrorHolder = {

0 commit comments

Comments
 (0)
Please sign in to comment.