File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,14 @@ function handleImportOutsideModuleError(stack: string, ctx: Vitest) {
150
150
else
151
151
name = name . split ( '/' ) [ 0 ]
152
152
153
- ctx . logger . error ( c . yellow (
153
+ if ( name )
154
+ printModuleWarningForPackage ( ctx . logger , path , name )
155
+ else
156
+ printModuleWarningForSourceCode ( ctx . logger , path )
157
+ }
158
+
159
+ function printModuleWarningForPackage ( logger : Logger , path : string , name : string ) {
160
+ logger . error ( c . yellow (
154
161
`Module ${ path } seems to be an ES Module but shipped in a CommonJS package. `
155
162
+ `You might want to create an issue to the package ${ c . bold ( `"${ name } "` ) } asking `
156
163
+ 'them to ship the file in .mjs extension or add "type": "module" in their package.json.'
@@ -170,6 +177,13 @@ function handleImportOutsideModuleError(stack: string, ctx: Vitest) {
170
177
}\n` ) ) )
171
178
}
172
179
180
+ function printModuleWarningForSourceCode ( logger : Logger , path : string ) {
181
+ logger . error ( c . yellow (
182
+ `Module ${ path } seems to be an ES Module but shipped in a CommonJS package. `
183
+ + 'To fix this issue, change the file extension to .mjs or add "type": "module" in your package.json.' ,
184
+ ) )
185
+ }
186
+
173
187
export function displayDiff ( diff : string , console : Console ) {
174
188
console . error ( diff )
175
189
}
You can’t perform that action at this time.
0 commit comments