react/create-react-app · error · Error
You specified ${type} in your env, but the file "${file}" ca
Error message
You specified ${type} in your env, but the file "${file}" can't be found. What it means
getHttpsConfig.readEnvFile is called with the value of an HTTPS-related env var (SSL_CRT_FILE or SSL_KEY_FILE) and a human label. If the path does not exist on disk (fs.existsSync returns false), it throws, telling the user which variable type they set and which file path could not be found.
Source
Thrown at packages/react-scripts/config/getHttpsConfig.js:45
);
}
try {
// privateDecrypt will throw an error with an invalid key
crypto.privateDecrypt(key, encrypted);
} catch (err) {
throw new Error(
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
err.message
}`
);
}
}
// Read file and throw an error if it doesn't exist
function readEnvFile(file, type) {
if (!fs.existsSync(file)) {
throw new Error(
`You specified ${chalk.cyan(
type
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
);
}
return fs.readFileSync(file);
}
// Get the https config
// Return cert files if provided in env, otherwise just true or false
function getHttpsConfig() {
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
const isHttps = HTTPS === 'true';
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
const config = {View on GitHub (pinned to 6254386531)
Solutions
- Confirm the file exists at the exact path: `ls -la $SSL_CRT_FILE $SSL_KEY_FILE`.
- Use paths relative to the project root (where react-scripts runs) or absolute paths that exist on this machine.
- Place cert/key in the project folder and reference them as `./cert.pem` / `./key.pem`.
- If you no longer need custom certs, unset SSL_CRT_FILE/SSL_KEY_FILE (and HTTPS) to let CRA generate one with selfsigned certs.
Example fix
# before SSL_CRT_FILE=/home/olduser/certs/localhost.crt # missing SSL_KEY_FILE=/home/olduser/certs/localhost.key # after SSL_CRT_FILE=./localhost.crt # exists in project root SSL_KEY_FILE=./localhost.key
Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const path = require('path');
function ensureSslFiles() {
for (const [type, file] of [
['SSL_CRT_FILE', process.env.SSL_CRT_FILE],
['SSL_KEY_FILE', process.env.SSL_KEY_FILE],
]) {
if (file && !fs.existsSync(path.resolve(process.cwd(), file))) {
throw new Error(`${type} '${file}' does not exist`);
}
}
}
ensureSslFiles(); Type guard
const sslFileExists = (file) => !file || fs.existsSync(path.resolve(process.cwd(), file));
Try / catch
try {
require('react-scripts/config/getHttpsConfig');
} catch (e) {
if (new RegExp("can't be found").test(e.message)) {
console.error('SSL_CRT_FILE/SSL_KEY_FILE path missing. Check .env paths.');
process.exit(1);
}
throw e;
} Prevention
- Store cert/key inside the project and reference them by relative path.
- Add a preflight check that the files exist before starting the dev server.
- Commit cert paths to .env but keep the files out of git (use a setup script).
- After cloning/moving a project, re-verify SSL_*_FILE paths.
When it happens
Trigger: Setting SSL_CRT_FILE or SSL_KEY_FILE (and HTTPS=true) in .env to a path that does not resolve from the project root. readEnvFile runs, fs.existsSync returns false, and the error is thrown.
Common situations: Typo in the path. Using a relative path that doesn't resolve from CWD. Moving the project without moving the cert files. Forgetting to commit/copy cert files in a fresh checkout. Absolute paths from another machine.
Related errors
- The certificate "${crtFile}" is invalid.\n${err.message}
- The certificate key "${keyFile}" is invalid.\n${err.message}
- Preset react-app: '${name}' option must be a boolean.
- Preset react-app: '${name}' option must be a boolean.
- The NODE_ENV environment variable is required but was not sp
AI-assisted analysis of react/create-react-app@6254386531 (2026-08-12).
Data as JSON: /api/errors/5abc5cf41214b9ab.
Report an issue: GitHub.