From 69258880244074eed6c3b05288eded2e4ed8102b Mon Sep 17 00:00:00 2001 From: Bojan Hribernik Date: Tue, 12 Jun 2018 01:25:01 +0200 Subject: [PATCH] Fix Cannot read property 'parent' of undefined in node This happens in webpack bundle in node server rendering react application: ```js TypeError: Cannot read property 'parent' of undefined at Object.eval (webpack:///./node_modules/paper/dist/node/self.js?:20:28) at eval (webpack:///./node_modules/paper/dist/node/self.js?:62:30) at Object../node_modules/paper/dist/node/self.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:34531:1) at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30) at Object.eval (webpack:///./node_modules/paper/dist/paper-core.js?:35:16) at eval (webpack:///./node_modules/paper/dist/paper-core.js?:14798:3) at Object../node_modules/paper/dist/paper-core.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:34553:1) at __webpack_require__ (/home/bojan/www/climbuddy/client/server/map.bundle.js:26:30) at eval (webpack:///./node_modules/react-paper-bindings/lib/View.js?:15:18) at Object../node_modules/react-paper-bindings/lib/View.js (/home/bojan/www/climbuddy/client/server/map.bundle.js:37188:1) ``` --- src/node/self.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/self.js b/src/node/self.js index 74a5f490..c8633cff 100644 --- a/src/node/self.js +++ b/src/node/self.js @@ -17,7 +17,7 @@ var path = require('path'); // Determine the name by which name the module was required (either 'paper', // 'paper-jsdom' or 'paper-jsdom-canvas'), and use this to determine if error // exceptions should be thrown or if loading should fail silently. -var parent = module.parent.parent, +var parent = module.parent ? module.parent.parent : null, requireName = parent && path.basename(path.dirname(parent.filename)); requireName = /^paper/.test(requireName) ? requireName : 'paper';