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

fix: don't print esm warning, if package name is not found #3292

Merged
merged 1 commit into from May 3, 2023
Merged
Changes from all commits
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
16 changes: 15 additions & 1 deletion packages/vitest/src/node/error.ts
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