appsmithorg/appsmith · 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`.

What it means

Thrown by getAdditionalModulePaths() in config/modules.js. The function resolves the tsconfig/jsconfig compilerOptions.baseUrl relative to the project root. It silently allows 'src' and 'node_modules' (handled above this snippet) and returns null when baseUrl equals the project root. For any other directory it throws, because CRA only supports absolute imports from src or node_modules — anything else would let webpack try to transpile files outside src.

Source

Thrown at app/client/config/modules.js:44

    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`.",
    ),
  );
}

/**
 * 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 8cd9021c24)

Solutions

  1. Set baseUrl to "src" (most common) so absolute imports resolve from src, e.g. import from 'Components/Button'.
  2. Or remove the baseUrl entirely and rely on CRA's default src-rooted absolute imports.
  3. For custom aliases, use the paths/compilerOptions.paths mapping with baseUrl 'src' instead of a custom baseUrl.
  4. If you genuinely need a non-src root, you are outside CRA's supported model — eject or use craco/react-app-rewired to override webpack resolve.alias.

Example fix

// before (tsconfig.json)
{
  "compilerOptions": { "baseUrl": "./app" }
}
// -> Your project's `baseUrl` can only be set to `src` or `node_modules`.

// after
{
  "compilerOptions": { "baseUrl": "src" }
}
Defensive patterns

Strategy: validation

Validate before calling

const path = require('path');
const tsConfig = require('./tsconfig.json');
const allowed = new Set(['src','node_modules']);
const base = tsConfig.compilerOptions?.baseUrl;
if (base && !allowed.has(path.basename(base)) && path.relative(process.cwd(), path.resolve(base)) !== '') {
  throw new Error('baseUrl must be src or node_modules');
}

Prevention

When it happens

Trigger: Setting compilerOptions.baseUrl in tsconfig.json or jsconfig.json to an arbitrary folder (e.g. 'app', 'lib', './src/components') that is neither 'src', 'node_modules', nor the project root.

Common situations: Copying a baseUrl from another project's config; IDE auto-generating a baseUrl pointing at a custom folder; migrating a non-CRA project that used baseUrl for path resolution; pointing baseUrl at a monorepo package root.

Related errors


AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12). Data as JSON: /api/errors/1995aa94b67db4cb. Report an issue: GitHub.