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 npm bug #5267

Merged
Merged
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion native.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,20 @@

const packageBase = imported.musl && isMusl() ? imported.musl : imported.base;
const localName = `./rollup.${packageBase}.node`;
const { parse, parseAsync, xxhashBase64Url } = require(
const requireWithFriendlyError = id => {
try {
return require(id);

Check warning on line 51 in native.js

View check run for this annotation

Codecov / codecov/patch

native.js#L51

Added line #L51 was not covered by tests
} catch (error) {
throw new Error(
`Cannot find module ${id}. ` +

Check warning on line 54 in native.js

View check run for this annotation

Codecov / codecov/patch

native.js#L54

Added line #L54 was not covered by tests
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
'If you are/were using them, please try `npm i` again after removing both package-lock.json and node_modules directory.',
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
{ cause: error }
);
}
};

const { parse, parseAsync, xxhashBase64Url } = requireWithFriendlyError(
existsSync(join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`
);

Expand Down