Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jan 27, 2022
1 parent 62e2a24 commit 6a76e27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions packages/yarnpkg-pnp/sources/loader/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ export function readPackage(requestPath: NativePath) {
// Our error isn't as detailed since we don't have access to acorn to check
// if the file contains ESM syntax
export function ERR_REQUIRE_ESM(filename: string, parentPath: string | null = null) {
const basename = parentPath && path.basename(filename) ===
path.basename(parentPath) ? filename : path.basename(filename);

let msg = `require() of ES Module ${filename}${parentPath ? ` from ${
parentPath}` : ``} not supported.`;
msg += `\nInstead change the require of ${basename} in ${parentPath} to` +
const basename =
parentPath && path.basename(filename) === path.basename(parentPath)
? filename
: path.basename(filename);

const msg =
`require() of ES Module ${filename}${parentPath ? ` from ${parentPath}` : ``} not supported.` +
`\nInstead change the require of ${basename} in ${parentPath} to` +
` a dynamic import() which is available in all CommonJS modules.`;

const err = new Error(msg) as Error & {code: string};
const err = new Error(msg) as Error & { code: string };
err.code = `ERR_REQUIRE_ESM`;
return err;
}

0 comments on commit 6a76e27

Please sign in to comment.