{"record":{"id":"0395285e64c32cd1","repo":"vercel/next.js","slug":"invalid-file-type","errorCode":null,"errorMessage":"Invalid file type {:?}","messagePattern":"Invalid file type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"turbopack/crates/turbopack-node/src/transforms/postcss.rs","lineNumber":323,"sourceCode":"    }\n}\n\n#[turbo_tasks::value_impl]\nimpl Asset for JsonSource {\n    #[turbo_tasks::function]\n    async fn content(&self) -> Result<Vc<AssetContent>> {\n        let file_type = &*self.path.get_type().await?;\n        match file_type {\n            FileSystemEntryType::File => {\n                let json = if self.allow_json5 {\n                    self.path.read_json5().content().await?\n                } else {\n                    self.path.read_json().content().await?\n                };\n                let value = match &*self.key.await? {\n                    Some(key) => {\n                        let Some(value) = json.get(&**key) else {\n                            anyhow::bail!(\"Invalid file type {:?}\", file_type)\n                        };\n                        value\n                    }\n                    None => &*json,\n                };\n                Ok(AssetContent::file(\n                    FileContent::Content(File::from(value.to_string())).cell(),\n                ))\n            }\n            FileSystemEntryType::NotFound => {\n                Ok(AssetContent::File(FileContent::NotFound.resolved_cell()).cell())\n            }\n            _ => bail!(\"Invalid file type {:?}\", file_type),\n        }\n    }\n}\n\n#[turbo_tasks::function]","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/turbopack/crates/turbopack-node/src/transforms/postcss.rs#L305-L341","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: package.json has no postcss field\n{ \"name\": \"app\", \"dependencies\": {} }\n\n// after\n{ \"name\": \"app\", \"postcss\": {}, \"dependencies\": {} }","handlingStrategy":"validation","validationCode":"// Before pointing the PostCSS loader at package.json, confirm the key exists.\nconst fs = require('fs');\nfunction ensureJsonKey(file, key) {\n  const json = JSON.parse(fs.readFileSync(file, 'utf8'));\n  if (!(key in json)) throw new Error(`${file} is missing required key \"${key}\"`);\n}\nensureJsonKey('./package.json', 'postcss');\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["postcss","json-config","config","misleading-message"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}