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
- Set baseUrl to "src" (most common) so absolute imports resolve from src, e.g. import from 'Components/Button'.
- Or remove the baseUrl entirely and rely on CRA's default src-rooted absolute imports.
- For custom aliases, use the paths/compilerOptions.paths mapping with baseUrl 'src' instead of a custom baseUrl.
- 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
- Keep baseUrl as 'src' or omit it.
- For custom aliases use compilerOptions.paths with baseUrl 'src'.
- Add a CI lint rule that fails if baseUrl is set to anything but src/node_modules.
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
- You have both a tsconfig.json and a jsconfig.json. If you ar
- The NODE_ENV environment variable is required but was not sp
- The certificate "${crtFile}" is invalid.\n${err.message}
- You specified ${type} in your env, but the file "${file}" ca
- Database URL not found. Please check APPSMITH_DB_URL or APPS
AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12).
Data as JSON: /api/errors/1995aa94b67db4cb.
Report an issue: GitHub.