Skip to content

Commit 33ce4ad

Browse files
committed
Prevent ReferenceError when runnin graphql in the browser
Not every user wants to or should use webpack to bundle graphql and related libs. Forcing web developers to cludge a global reference to an imaginary `process` in a render-blocking script is not an optimal solution, when libraries can just check it themselves.
1 parent 7fff8b7 commit 33ce4ad

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/jsutils/instanceOf.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ declare function instanceOf(
1616
constructor: mixed,
1717
): boolean %checks(value instanceof constructor);
1818

19+
/* global window */
20+
// window is undefined on node, let's not trip the linter.
21+
let glbl;
22+
try {
23+
glbl = global;
24+
} catch (e) {
25+
glbl = window
26+
}
27+
1928
// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
2029
// See: https://webpack.js.org/guides/production/
21-
export default (process.env.NODE_ENV === 'production'
30+
export default (glbl.process && glbl.process.env.NODE_ENV === 'production'
2231
? // eslint-disable-next-line no-shadow
2332
function instanceOf(value: mixed, constructor: mixed) {
2433
return value instanceof constructor;

0 commit comments

Comments
 (0)