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 friendly error for missing MSVC redistributable #5284

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
22 changes: 22 additions & 0 deletions native.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
}
};

const msvcLinkFilenameByArch = {
arm64: 'vc_redist.arm64.exe',
ia32: 'vc_redist.x86.exe',
x64: 'vc_redist.x64.exe'
};

const packageBase = getPackageBase();

if (!packageBase) {
Expand Down Expand Up @@ -61,6 +67,22 @@
try {
return require(id);
} catch (error) {
if (

Check warning on line 70 in native.js

View check run for this annotation

Codecov / codecov/patch

native.js#L70

Added line #L70 was not covered by tests
platform === 'win32' &&
error instanceof Error &&
error.code === 'ERR_DLOPEN_FAILED' &&
error.message.includes('The specified module could not be found')
) {
const msvcDownloadLink = `https://aka.ms/vs/17/release/${msvcLinkFilenameByArch[arch]}`;
throw new Error(

Check warning on line 77 in native.js

View check run for this annotation

Codecov / codecov/patch

native.js#L76-L77

Added lines #L76 - L77 were not covered by tests
`Failed to load module ${id}. ` +
'Required DLL was not found. ' +
'This error usually happens when Microsoft Visual C++ Redistributable is not installed. ' +
`You can download it from ${msvcDownloadLink}`,
{ cause: error }
);
}

throw new Error(
`Cannot find module ${id}. ` +
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
Expand Down