Skip to content

Commit

Permalink
fix: don't print esm warning, if package name is not found (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored May 3, 2023
1 parent 19fcd8d commit 62c14cb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/vitest/src/node/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ function handleImportOutsideModuleError(stack: string, ctx: Vitest) {
else
name = name.split('/')[0]

ctx.logger.error(c.yellow(
if (name)
printModuleWarningForPackage(ctx.logger, path, name)
else
printModuleWarningForSourceCode(ctx.logger, path)
}

function printModuleWarningForPackage(logger: Logger, path: string, name: string) {
logger.error(c.yellow(
`Module ${path} seems to be an ES Module but shipped in a CommonJS package. `
+ `You might want to create an issue to the package ${c.bold(`"${name}"`)} asking `
+ 'them to ship the file in .mjs extension or add "type": "module" in their package.json.'
Expand All @@ -170,6 +177,13 @@ function handleImportOutsideModuleError(stack: string, ctx: Vitest) {
}\n`)))
}

function printModuleWarningForSourceCode(logger: Logger, path: string) {
logger.error(c.yellow(
`Module ${path} seems to be an ES Module but shipped in a CommonJS package. `
+ 'To fix this issue, change the file extension to .mjs or add "type": "module" in your package.json.',
))
}

export function displayDiff(diff: string, console: Console) {
console.error(diff)
}
Expand Down

0 comments on commit 62c14cb

Please sign in to comment.