File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -416,13 +416,23 @@ function createBundle(bundle, bundleType) {
416
416
console . error ( error . message ) ;
417
417
418
418
const { file, line, column} = error . loc ;
419
- const rawLines = fs . readFileSync ( file , 'utf-8' ) ;
420
- // column + 1 is required due to rollup counting column start position from 0
421
- // whereas babel-code-frame counts from 1
422
- const frame = codeFrame ( rawLines , line , column + 1 , {
423
- highlightCode : true ,
424
- } ) ;
425
- console . error ( frame ) ;
419
+ if ( file ) {
420
+ // This looks like an error from Rollup, e.g. missing export.
421
+ // We'll use the accurate line numbers provided by Rollup but
422
+ // use Babel code frame because it looks nicer.
423
+ const rawLines = fs . readFileSync ( file , 'utf-8' ) ;
424
+ // column + 1 is required due to rollup counting column start position from 0
425
+ // whereas babel-code-frame counts from 1
426
+ const frame = codeFrame ( rawLines , line , column + 1 , {
427
+ highlightCode : true ,
428
+ } ) ;
429
+ console . error ( frame ) ;
430
+ } else {
431
+ // This looks like an error from a plugin (e.g. Babel).
432
+ // In this case we'll resort to displaying the provided code frame
433
+ // because we can't be sure the reported location is accurate.
434
+ console . error ( error . codeFrame ) ;
435
+ }
426
436
} else {
427
437
console . error ( error ) ;
428
438
}
You can’t perform that action at this time.
0 commit comments