Fail build on deep requires in npm packages (#21063)

This commit is contained in:
Dan Abramov 2021-03-24 02:43:55 +00:00 committed by GitHub
parent 2c9d8efc8e
commit 7b84dbd169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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];