Skip to content

Commit

Permalink
improve and align error message
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 18, 2021
1 parent ea9f5c4 commit 1ca9f85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/library/AssignLibraryPlugin.js
Expand Up @@ -94,6 +94,9 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
* @property {string | string[]} name
*/

const COMMON_LIBRARY_NAME_MESSAGE =
"Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'.";

/**
* @typedef {AssignLibraryPluginParsed} T
* @extends {AbstractLibraryPlugin<AssignLibraryPluginParsed>}
Expand All @@ -120,12 +123,14 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
const { name } = library;
if (this.unnamed === "error") {
if (typeof name !== "string" && !Array.isArray(name)) {
throw new Error("output.library.name must be a string or string array");
throw new Error(
`Library name must be a string or string array. ${COMMON_LIBRARY_NAME_MESSAGE}`
);
}
} else {
if (name && typeof name !== "string" && !Array.isArray(name)) {
throw new Error(
"output.library.name must be a string, string array or unset"
`Library name must be a string, string array or unset. ${COMMON_LIBRARY_NAME_MESSAGE}`
);
}
}
Expand Down Expand Up @@ -158,7 +163,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
throw new Error(
`Library name base (${base}) must be a valid identifier when using a var declaring library type. Either use a valid identifier (e. g. ${Template.toIdentifier(
base
)}) or use a different library type (e. g. 'type: "global"', which assign a property on the global scope instead of declaring a variable). Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'.`
)}) or use a different library type (e. g. 'type: "global"', which assign a property on the global scope instead of declaring a variable). ${COMMON_LIBRARY_NAME_MESSAGE}`
);
}
result.add(`${this.declare} ${base};`);
Expand Down
4 changes: 2 additions & 2 deletions test/Errors.test.js
Expand Up @@ -881,8 +881,8 @@ describe("loaders", () => {
})
).rejects.toMatchInlineSnapshot(`
Object {
"message": "output.library.name must be a string or string array",
"stack": "Error: output.library.name must be a string or string array",
"message": "Library name must be a string or string array. Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'.",
"stack": "Error: Library name must be a string or string array. Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'.",
}
`);
});
Expand Down

0 comments on commit 1ca9f85

Please sign in to comment.