From 9561d662d70357afd75e472c29f98c618a644680 Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Sat, 2 Nov 2019 18:21:32 +1100 Subject: [PATCH] fix: explain why RHL could not be activated, fixes #1362 --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 98dde5a8a..ab75c7e99 100644 --- a/index.js +++ b/index.js @@ -13,18 +13,28 @@ if (process.env.NODE_ENV === 'production') { module.exports.hot.shouldWrapWithAppContainer = true; } else { var evalAllowed = false; + var evalError = null; try { eval('evalAllowed = true'); } catch (e) { // eval not allowed due to CSP + evalError = e && e.message ? e.message : 'unknown reason'; } + // TODO: dont use eval to update methods. see #1273 // RHL needs setPrototypeOf to operate Component inheritance, and eval to patch methods var jsFeaturesPresent = !!Object.setPrototypeOf; if (!jsFeaturesPresent || !evalAllowed) { // we are not in prod mode, but RHL could not be activated - console.warn('React-Hot-Loader is not supported in this environment.'); + console.warn( + 'React-Hot-Loader is not supported in this environment:', + [ + !jsFeaturesPresent && "some JS features are missing", + !evalAllowed && "`eval` is not allowed(" + evalError + ")" + ].join(','), + '.' + ); module.exports = require('./dist/react-hot-loader.production.min.js'); } else { module.exports = window.reactHotLoaderGlobal = require('./dist/react-hot-loader.development.js');