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

Add diagnostic for failed autoinstall of node polyfill #7682

Merged
merged 1 commit into from Feb 10, 2022
Merged
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
28 changes: 27 additions & 1 deletion packages/utils/node-resolver-core/src/NodeResolver.js
Expand Up @@ -290,6 +290,7 @@ export default class NodeResolver {

// Auto install node builtin polyfills if not already available
if (resolved === undefined && builtin != null) {
let packageName = builtin.split('/')[0];
let packageManager = this.packageManager;
if (packageManager) {
this.logger?.warn({
Expand All @@ -312,7 +313,7 @@ export default class NodeResolver {
'https://parceljs.org/features/node-emulation/#polyfilling-%26-excluding-builtin-node-modules',
});

await packageManager.resolve(builtin, this.projectRoot + '/index', {
await packageManager.resolve(packageName, this.projectRoot + '/index', {
saveDev: true,
shouldAutoInstall: true,
});
Expand All @@ -323,6 +324,31 @@ export default class NodeResolver {
} catch (err) {
// ignore
}
} else {
throw new ThrowableDiagnostic({
diagnostic: {
message: md`Node builtin polyfill "${packageName}" is not installed, but auto install is disabled.`,
codeFrames: [
{
filePath: ctx.loc?.filePath ?? sourceFile,
codeHighlights: ctx.loc
? [
{
message: 'used here',
start: ctx.loc.start,
end: ctx.loc.end,
},
]
: [],
},
],
documentationURL:
'https://parceljs.org/features/node-emulation/#polyfilling-%26-excluding-builtin-node-modules',
hints: [
md`Install the "${packageName}" package with your package manager, and run Parcel again.`,
],
},
});
}
}

Expand Down