Merge pull request #11131 from webpack/bugfix/ignore-linking-errors-on-error

ignore linking errors when the imported module has errors
This commit is contained in:
Tobias Koppers 2020-07-09 10:22:35 +02:00 committed by GitHub
commit 49e5ce2812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 51 additions and 11 deletions

View File

@ -433,6 +433,13 @@ class Module extends DependenciesBlock {
return this._warnings;
}
/**
* @returns {number} number of warnings
*/
getNumberOfWarnings() {
return this._warnings !== undefined ? this._warnings.length : 0;
}
/**
* @param {WebpackError} error the error
* @returns {void}
@ -451,6 +458,13 @@ class Module extends DependenciesBlock {
return this._errors;
}
/**
* @returns {number} number of errors
*/
getNumberOfErrors() {
return this._errors !== undefined ? this._errors.length : 0;
}
/**
* removes all warnings and errors
* @returns {void}

View File

@ -95,7 +95,8 @@ class HarmonyImportDependency extends ModuleDependency {
*/
getLinkingErrors(moduleGraph, ids, additionalMessage) {
const importedModule = moduleGraph.getModule(this);
if (!importedModule) {
// ignore errors for missing or failed modules
if (!importedModule || importedModule.getNumberOfErrors() > 0) {
return;
}

View File

@ -1,5 +0,0 @@
module.exports = [
[/export 'default' \(imported as 'a'\) was not found in '\.\/loader!\.\/a'/],
[/export 'default' \(imported as 'a'\) was not found in '\.\/loader!\.\/a'/],
[/export 'default' \(imported as 'a'\) was not found in '\.\/loader!\.\/a'/]
]

View File

@ -1,5 +0,0 @@
module.exports = [
[/export 'default' \(imported as 'a'\) was not found in '\.\/a'/],
[/export 'default' \(imported as 'a'\) was not found in '\.\/a'/],
[/export 'default' \(imported as 'a'\) was not found in '\.\/a'/]
]

View File

@ -0,0 +1 @@
module.exports = [[/Module parse failed/]];

View File

@ -0,0 +1,26 @@
it("should recover from syntax error in module", async () => {
switch (WATCH_STEP) {
case "0":
case "2":
await expect(import("test-module")).rejects.toEqual(
expect.objectContaining({
message: expect.stringContaining("Module parse failed")
})
);
break;
case "1":
await expect(import("test-module")).resolves.toEqual(
expect.objectContaining({
default: 42
})
);
break;
case "3":
await expect(import("test-module")).resolves.toEqual(
expect.objectContaining({
default: 43
})
);
break;
}
});

View File

@ -0,0 +1 @@
export default 42*;

View File

@ -0,0 +1 @@
export { default as default } from "some-module";

View File

@ -0,0 +1 @@
export default 42;

View File

@ -0,0 +1 @@
module.exports = [[/Module parse failed/]];

View File

@ -0,0 +1 @@
export default 42*;

View File

@ -0,0 +1 @@
export default 43;

2
types.d.ts vendored
View File

@ -3890,8 +3890,10 @@ declare class Module extends DependenciesBlock {
addPresentationalDependency(presentationalDependency: Dependency): void;
addWarning(warning: WebpackError): void;
getWarnings(): Iterable<WebpackError>;
getNumberOfWarnings(): number;
addError(error: WebpackError): void;
getErrors(): Iterable<WebpackError>;
getNumberOfErrors(): number;
/**
* removes all warnings and errors