react/create-react-app · error · Error

Your project's `baseUrl` can only be set to `src` or `node_m

Error message

Your project's `baseUrl` can only be set to `src` or `node_modules`. Create React App does not support other values at this time.

What it means

modules.getModules resolves the `baseUrl` from tsconfig.json/jsconfig.json compilerOptions relative to the project path. CRA only supports `src` or `node_modules` as baseUrl because source outside `src` is not transpiled. Any other resolved baseUrl (that isn't the project root, which is ignored) triggers this error.

Source

Thrown at packages/react-scripts/config/modules.js:52

    return null;
  }

  // Allow the user set the `baseUrl` to `appSrc`.
  if (path.relative(paths.appSrc, baseUrlResolved) === '') {
    return [paths.appSrc];
  }

  // If the path is equal to the root directory we ignore it here.
  // We don't want to allow importing from the root directly as source files are
  // not transpiled outside of `src`. We do allow importing them with the
  // absolute path (e.g. `src/Components/Button.js`) but we set that up with
  // an alias.
  if (path.relative(paths.appPath, baseUrlResolved) === '') {
    return null;
  }

  // Otherwise, throw an error.
  throw new Error(
    chalk.red.bold(
      "Your project's `baseUrl` can only be set to `src` or `node_modules`." +
        ' Create React App does not support other values at this time.'
    )
  );
}

/**
 * Get webpack aliases based on the baseUrl of a compilerOptions object.
 *
 * @param {*} options
 */
function getWebpackAliases(options = {}) {
  const baseUrl = options.baseUrl;

  if (!baseUrl) {
    return {};
  }

View on GitHub (pinned to 6254386531)

Solutions

  1. Set baseUrl to 'src' (most common CRA setup): `{ "compilerOptions": { "baseUrl": "src" } }`.
  2. Or remove baseUrl entirely if you don't need non-relative imports.
  3. If you need path aliases, keep baseUrl='src' and add `paths` mappings relative to it.
  4. Ensure baseUrl is not set to '.', '..', or a custom folder name.

Example fix

// before  (tsconfig.json)
{
  "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["src/*"] } }
}
// after
{
  "compilerOptions": { "baseUrl": "src", "paths": { "@/*": ["./*"] } }
}
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
const ALLOWED = ['src', 'node_modules'];
function validateBaseUrl(tsConfigPath = 'tsconfig.json') {
  const cfg = JSON.parse(fs.readFileSync(tsConfigPath, 'utf8'));
  const baseUrl = cfg && cfg.compilerOptions && cfg.compilerOptions.baseUrl;
  if (baseUrl && !ALLOWED.includes(baseUrl) && baseUrl !== '.') {
    throw new Error(`baseUrl '${baseUrl}' not supported by CRA. Use 'src' or 'node_modules'.`);
  }
}
validateBaseUrl();

Type guard

const isAllowedBaseUrl = (b) =>
  b === undefined || b === 'src' || b === 'node_modules' || b === '.';

Try / catch

try {
  require('react-scripts/config/modules').getModules();
} catch (e) {
  if (/baseUrl/.test(e.message)) {
    console.error('Set tsconfig/jsconfig baseUrl to src or node_modules.');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Setting `compilerOptions.baseUrl` in tsconfig.json or jsconfig.json to a directory other than `src`, `node_modules`, or the project root. The resolver computes baseUrlResolved, the relative path is non-empty and not 'src'/'node_modules', so the final throw runs.

Common situations: Copying a tsconfig from a non-CRA project that points baseUrl at `.` or a custom folder. Adding path mappings that imply a different baseUrl. Ejecting and bringing in outside conventions. IDE auto-generation of jsconfig with baseUrl='.'.

Related errors


AI-assisted analysis of react/create-react-app@6254386531 (2026-08-12). Data as JSON: /api/errors/3b65ceae9d937bbc. Report an issue: GitHub.