Skip to content

Commit

Permalink
Add friendly error for missing MSVC redistributable
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 5, 2023
1 parent 0b619fd commit e01b7dc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions native.js
Expand Up @@ -25,6 +25,12 @@ const bindingsByPlatformAndArch = {
}
};

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 @@ const requireWithFriendlyError = id => {
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

0 comments on commit e01b7dc

Please sign in to comment.