@@ -310,15 +310,20 @@ export function getParserSync(file: string, options?: ParserOptions): Parser {
310310 basedir : parentDir ,
311311 } )
312312 // eslint-disable-next-line @typescript-eslint/no-var-requires
313- const babel = require ( babelPath )
313+ const babel = require ( /* webpackIgnore: true */ babelPath )
314314 requiredPaths . push ( babelPath )
315315
316- const parserPath = _resolve . sync ( '@babel/parser' , {
317- basedir : parentDir ,
318- } )
319- // eslint-disable-next-line @typescript-eslint/no-var-requires
320- const parser = require ( parserPath )
321- requiredPaths . push ( parserPath )
316+ let parser : typeof defaultBabelParser
317+ try {
318+ const parserPath = _resolve . sync ( '@babel/parser' , {
319+ basedir : parentDir ,
320+ } )
321+ // eslint-disable-next-line @typescript-eslint/no-var-requires
322+ parser = require ( /* webpackIgnore: true */ parserPath )
323+ requiredPaths . push ( parserPath )
324+ } catch ( error ) {
325+ parser = defaultBabelParser
326+ }
322327
323328 const loadOpts = {
324329 filename : file ,
@@ -364,14 +369,19 @@ export async function getParserAsync(
364369 const babelPath = await resolve ( '@babel/core' , {
365370 basedir : parentDir ,
366371 } )
367- const babel = await import ( babelPath )
372+ const babel = await import ( /* webpackIgnore: true */ babelPath )
368373 requiredPaths . push ( babelPath )
369374
370- const parserPath = await resolve ( '@babel/parser' , {
371- basedir : parentDir ,
372- } )
373- const parser = await import ( parserPath )
374- requiredPaths . push ( parserPath )
375+ let parser : typeof defaultBabelParser
376+ try {
377+ const parserPath = await resolve ( '@babel/parser' , {
378+ basedir : parentDir ,
379+ } )
380+ parser = await import ( /* webpackIgnore: true */ parserPath )
381+ requiredPaths . push ( parserPath )
382+ } catch ( error ) {
383+ parser = defaultBabelParser
384+ }
375385
376386 const loadOpts = {
377387 filename : file ,
0 commit comments