diff --git a/packages/babel-polyfill/noConflict.js b/packages/babel-polyfill/noConflict.js new file mode 100644 index 0000000000..f6b971bb15 --- /dev/null +++ b/packages/babel-polyfill/noConflict.js @@ -0,0 +1 @@ +require("./lib/noConflict"); diff --git a/packages/babel-polyfill/src/index.js b/packages/babel-polyfill/src/index.js index f4057ecb6a..5661b7c75a 100644 --- a/packages/babel-polyfill/src/index.js +++ b/packages/babel-polyfill/src/index.js @@ -1,7 +1,13 @@ -if (global._babelPolyfill) { - throw new Error("only one instance of @babel/polyfill is allowed"); -} -global._babelPolyfill = true; - import "core-js/shim"; import "regenerator-runtime/runtime"; + +if (global._babelPolyfill && typeof console !== "undefined" && console.warn) { + console.warn( + "@babel/polyfill is loaded more than once on this page. This is probably not desirable/intended " + + "and may have consequences if different versions of the polyfills are applied sequentially. " + + "If you do need to load the polyfill more than once, use @babel/polyfill/noConflict " + + "instead to bypass the warning.", + ); +} + +global._babelPolyfill = true; diff --git a/packages/babel-polyfill/src/noConflict.js b/packages/babel-polyfill/src/noConflict.js new file mode 100644 index 0000000000..ae74735ec3 --- /dev/null +++ b/packages/babel-polyfill/src/noConflict.js @@ -0,0 +1,2 @@ +import "core-js/shim"; +import "regenerator-runtime/runtime";