oklas / react-app-alias

:label: Alias and multiple src directory for craco or rewired create-react-app
MIT License
173 stars 18 forks source link

Cannot read property 'baseUrl' of undefined #93

Open namnm opened 1 year ago

namnm commented 1 year ago
node_modules/react-app-alias/src/index.js:199
    baseUrl: conf.compilerOptions.baseUrl || '.',
                                  ^

The config fully extends from another, there is no compilerOptions when using console.log to see:

{
  extends: {
    compilerOptions: {
      module: 'esnext',
      target: 'es5',
      lib: [Array],
      allowJs: false,
      checkJs: false,
      resolveJsonModule: true,
      jsx: 'react-jsx',
      declaration: false,
      declarationMap: false,
      sourceMap: false,
      noEmit: true,
      isolatedModules: true,
      skipLibCheck: true,
      strict: true,
      noImplicitAny: false,
      strictNullChecks: true,
      strictFunctionTypes: true,
      strictPropertyInitialization: false,
      noImplicitThis: true,
      alwaysStrict: true,
      forceConsistentCasingInFileNames: true,
      noImplicitReturns: true,
      noFallthroughCasesInSwitch: true,
      moduleResolution: 'node',
      paths: [Object],
      allowSyntheticDefaultImports: true,
      esModuleInterop: true,
      experimentalDecorators: false,
      emitDecoratorMetadata: false
    },
    include: [ './**/*' ]
  }
}

This can be fixed by using a condition?

let compilerOptions = conf.compilerOptions
if (!compilerOptions && conf.extends) {
  compilerOptions = conf.extends.compilerOptions
}
let baseUrl
if (compilerOptions) {
  baseUrl = compilerOptions.baseUrl
}
if (!baseUrl) {
  baseUrl = '.'
}