MCPcopy
hub / github.com/rollup/rollup / requireWithFriendlyError

Function requireWithFriendlyError

native.js:101–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99const packageBase = getPackageBase();
100const localName = `./rollup.${packageBase}.node`;
101const requireWithFriendlyError = id => {
102 try {
103 return require(id);
104 } catch (error) {
105 if (
106 platform === 'win32' &&
107 error instanceof Error &&
108 error.code === 'ERR_DLOPEN_FAILED' &&
109 error.message.includes('The specified module could not be found')
110 ) {
111 const msvcDownloadLink = `https://aka.ms/vs/17/release/${msvcLinkFilenameByArch[arch]}`;
112 throw new Error(
113 `Failed to load module ${id}. ` +
114 'Required DLL was not found. ' +
115 'This error usually happens when Microsoft Visual C++ Redistributable is not installed. ' +
116 `You can download it from ${msvcDownloadLink}`,
117 { cause: error }
118 );
119 }
120
121 throw new Error(
122 `Cannot find module ${id}. ` +
123 `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
124 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
125 { cause: error }
126 );
127 }
128};
129
130const { parse, parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } = requireWithFriendlyError(
131 existsSync(path.join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`

Callers 1

native.jsFile · 0.85

Calls 1

requireFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…