From 7b84dbd1697609d4df5931422c9591fe62022cb9 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 24 Mar 2021 02:43:55 +0000 Subject: [PATCH] Fail build on deep requires in npm packages (#21063) --- scripts/rollup/build.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index d25110eed892a..41b0685098fa0 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -582,6 +582,17 @@ async function createBundle(bundle, bundleType) { const containsThisModule = pkg => id === pkg || id.startsWith(pkg + '/'); const isProvidedByDependency = externals.some(containsThisModule); if (!shouldBundleDependencies && isProvidedByDependency) { + if (id.indexOf('/src/') !== -1) { + throw Error( + 'You are trying to import ' + + id + + ' but ' + + externals.find(containsThisModule) + + ' is one of npm dependencies, ' + + 'so it will not contain that source file. You probably want ' + + 'to create a new bundle entry point for it instead.' + ); + } return true; } return !!peerGlobals[id];