Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest -transform- when resolving missing plugins #15683

Merged
merged 2 commits into from Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/babel-core/src/config/files/plugins.ts
Expand Up @@ -111,6 +111,22 @@ function* resolveAlternativesHelper(
error.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`;
}

if (type === "plugin") {
const transformName = standardizedName.replace("-proposal-", "-transform-");
if (transformName !== standardizedName && !(yield transformName).error) {
error.message += `\n- Did you mean "${transformName}"?`;
}
}

error.message += `\n
Make sure that all the Babel plugins and presets you are using
are defined as dependencies or devDependencies in your package.json
file. It's possible that the missing plugin is loaded by a preset
you are using that forgot to add the plugin to its dependencies: you
can workaround this problem by explicitly adding the missing package
to your top-level package.json.
`;

throw error;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/babel-core/test/resolution.js
Expand Up @@ -466,6 +466,22 @@ describe("addon resolution", function () {

const nodeGte12 = parseInt(process.versions.node, 10) >= 12 ? it : it.skip;

nodeGte12(
"should suggest -transform- as an alternative to -proposal-",
function () {
process.chdir("throw-proposal-to-transform");

expect(() => {
babel.transformSync("", {
filename: "filename.js",
configFile: false,
plugins: ["@babel/proposal-halting-functions"],
});
}).toThrow(
/Cannot (?:find|resolve) module '@babel\/plugin-proposal-halting-functions'.*\n- Did you mean "@babel\/plugin-transform-halting-functions"\?/s,
);
},
);
nodeGte12("should respect package.json#exports", async function () {
process.chdir("pkg-exports");

Expand Down