vercel/next.js · error
Invalid file type {:?}
Error message
Invalid file type {:?} What it means
JsonSource::content() loads a JSON file (typically package.json) and extracts a specific sub-key (e.g. the 'postcss' field). When the requested key is not present in the parsed JSON object, it bails with 'Invalid file type {:?}'. Note the message text is misleading — file_type is always File at this point; the real condition is a missing JSON key. A second occurrence (line 336) fires for genuinely non-file entry types (directories, symlinks).
Source
Thrown at turbopack/crates/turbopack-node/src/transforms/postcss.rs:323
}
}
#[turbo_tasks::value_impl]
impl Asset for JsonSource {
#[turbo_tasks::function]
async fn content(&self) -> Result<Vc<AssetContent>> {
let file_type = &*self.path.get_type().await?;
match file_type {
FileSystemEntryType::File => {
let json = if self.allow_json5 {
self.path.read_json5().content().await?
} else {
self.path.read_json().content().await?
};
let value = match &*self.key.await? {
Some(key) => {
let Some(value) = json.get(&**key) else {
anyhow::bail!("Invalid file type {:?}", file_type)
};
value
}
None => &*json,
};
Ok(AssetContent::file(
FileContent::Content(File::from(value.to_string())).cell(),
))
}
FileSystemEntryType::NotFound => {
Ok(AssetContent::File(FileContent::NotFound.resolved_cell()).cell())
}
_ => bail!("Invalid file type {:?}", file_type),
}
}
}
#[turbo_tasks::function]View on GitHub (pinned to 0ae8c72462)
Solutions
- Add the expected key (e.g. "postcss": {}) to package.json, or point the config search at a dedicated postcss.config.js.
- Verify the configured PostCSS config path resolves to a regular file, not a directory.
- If the key is intentionally absent, remove the package.json from the config-search candidates.
Example fix
// before: package.json has no postcss field
{ "name": "app", "dependencies": {} }
// after
{ "name": "app", "postcss": {}, "dependencies": {} } Defensive patterns
Strategy: validation
Validate before calling
// Before pointing the PostCSS loader at package.json, confirm the key exists.
const fs = require('fs');
function ensureJsonKey(file, key) {
const json = JSON.parse(fs.readFileSync(file, 'utf8'));
if (!(key in json)) throw new Error(`${file} is missing required key "${key}"`);
}
ensureJsonKey('./package.json', 'postcss');
Prevention
- Prefer a dedicated postcss.config.js over a package.json "postcss" field to avoid ambiguity.
- If using package.json, ensure the postcss key is present and an object.
- Keep config-search roots minimal so unrelated package.json files aren't picked up.
When it happens
Trigger: A package.json is selected as a PostCSS config source and a key (e.g. 'postcss') is requested, but that key does not exist in the JSON object. Also when the resolved path is a directory or symlink rather than a regular file.
Common situations: A monorepo where package.json exists but lacks a 'postcss' field yet is still picked up by the config search; renaming or removing the postcss config key while the loader still targets package.json; a config path resolving to a directory.
Related errors
- `forbidden()` is experimental and only allowed to be enabled
- `unauthorized()` is experimental and only allowed to be used
- NEXT_EXPORT_ERROR
- Failed to resolve pattern "${patterns.join(',')}": ${error.m
- The key "${key}" under "env" in ${config.configFileName || '
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/0395285e64c32cd1.
Report an issue: GitHub.