From 73f784e49f5325940d5b2dd064de638caa59d7fd Mon Sep 17 00:00:00 2001 From: Martin Jantosovic Date: Thu, 23 Sep 2021 17:37:37 +0200 Subject: [PATCH 1/2] fix: Clear correct cache when compiling with Webpack --- packages/server/src/util.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/server/src/util.js b/packages/server/src/util.js index e181351c..b13a121f 100644 --- a/packages/server/src/util.js +++ b/packages/server/src/util.js @@ -1,5 +1,11 @@ +// Use __non_webpack_require__ to prevent Webpack from compiling it +// when the server-side code is compiled with Webpack +// eslint-disable-next-line camelcase, no-undef, global-require, import/no-dynamic-require, no-eval +const getRequire = () => typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : eval('require'); + export const clearModuleCache = moduleName => { - const m = require.cache[moduleName] + const { cache } = getRequire(); + const m = cache[moduleName] if (m) { // remove self from own parents if (m.parent && m.parent.children) { @@ -13,7 +19,7 @@ export const clearModuleCache = moduleName => { } }) } - delete require.cache[moduleName] + delete cache[moduleName] } } @@ -22,16 +28,7 @@ export const smartRequire = modulePath => { clearModuleCache(modulePath) } - // Use __non_webpack_require__ to prevent Webpack from compiling it - // when the server-side code is compiled with Webpack - // eslint-disable-next-line camelcase - if (typeof __non_webpack_require__ !== 'undefined') { - // eslint-disable-next-line no-undef - return __non_webpack_require__(modulePath) - } - - // eslint-disable-next-line global-require, import/no-dynamic-require, no-eval - return eval('require')(modulePath) + return getRequire(modulePath) } export const joinURLPath = (publicPath, filename) => { From 5d9efc0ed2035fcbeacaa13fff3db029585e7340 Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Sun, 26 Sep 2021 13:44:57 +1000 Subject: [PATCH 2/2] Update packages/server/src/util.js --- packages/server/src/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/util.js b/packages/server/src/util.js index b13a121f..bbe113a4 100644 --- a/packages/server/src/util.js +++ b/packages/server/src/util.js @@ -28,7 +28,7 @@ export const smartRequire = modulePath => { clearModuleCache(modulePath) } - return getRequire(modulePath) + return getRequire()(modulePath) } export const joinURLPath = (publicPath, filename) => {