{"record":{"id":"8f35754614a5cfbb","repo":"vercel/next.js","slug":"failed-to-convert-rope-into-string","errorCode":null,"errorMessage":"failed to convert rope into string","messagePattern":"failed to convert rope into string","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"turbopack/crates/turbopack-ecmascript/src/parse.rs","lineNumber":396,"sourceCode":"\nasync fn parse_file_content(\n    program_source: Rope,\n    fs_path: &FileSystemPath,\n    ident: &str,\n    query: RcStr,\n    file_path_hash: u128,\n    source: ResolvedVc<Box<dyn Source>>,\n    ty: EcmascriptModuleAssetType,\n    transforms: &[EcmascriptInputTransform],\n    node_env: RcStr,\n    loose_errors: bool,\n    inline_helpers: bool,\n) -> Result<Vc<ParseResult>> {\n    let string = match BytesStr::from_utf8(program_source.clone().into_bytes()) {\n        Ok(s) => s,\n        Err(error) => {\n            let error: RcStr = PrettyPrintError(\n                &anyhow::anyhow!(error).context(\"failed to convert rope into string\"),\n            )\n            .to_string()\n            .into();\n            ReadSourceIssue {\n                // Technically we could supply byte offsets to the issue source, but\n                // that would cause another utf8 error to be produced when we\n                // attempt to infer line/column\n                // offsets\n                source: IssueSource::from_source_only(source),\n                error: error.clone(),\n                severity: if loose_errors {\n                    IssueSeverity::Warning\n                } else {\n                    IssueSeverity::Error\n                },\n            }\n            .resolved_cell()\n            .emit();","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/turbopack/crates/turbopack-ecmascript/src/parse.rs#L378-L414","documentation":"While parsing an ECMAScript module, Turbopack converts the file content (held in a Rope) to a UTF-8 string via BytesStr::from_utf8. If the bytes are not valid UTF-8, conversion fails. Rather than crashing, Turbopack emits an Issue (Warning when loose_errors is set, Error otherwise), reports the source location, and marks the file as Unparsable so the build can continue or fail gracefully.","triggerScenarios":"A .js/.jsx/.ts/.tsx/.mjs/.cjs file containing byte sequences that are not valid UTF-8 — e.g. Latin-1/GBK/Shift-JIS encoded text, binary content accidentally given a JS extension, or a file corrupted during git transfer/merge.","commonSituations":"Source files saved by editors using a legacy locale encoding on Windows; binary blobs mislabeled with a script extension; files damaged by incorrect line-ending or encoding normalization; vendored third-party code containing mojibake.","solutions":["Re-save the offending file as UTF-8 (most editors offer 'Save with Encoding → UTF-8').","Verify the file is actually source code and not binary; check its first bytes with a hex viewer.","If vendored, re-fetch the package from npm or re-clone the file from git to undo corruption.","Add a `.gitattributes` rule (`*.js text eol=lf`) to prevent encoding/line-ending mangling."],"exampleFix":"# terminal: re-encode the file to UTF-8\niconv -f LATIN1 -t UTF-8 bad.js > fixed.js && mv fixed.js bad.js","handlingStrategy":"validation","validationCode":"// Pre-check that a source file is valid UTF-8 before bundling (Node.js).\nconst fs = require('fs');\nfunction assertUtf8(file) {\n  const buf = fs.readFileSync(file);\n  // Node throws on invalid sequences when decoding\n  new TextDecoder('utf-8', { fatal: true }).decode(buf);\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure your editor and CI to enforce UTF-8 encoding for all source files.","Add `.gitattributes` rules (`* text=auto eol=lf`) so git never re-encodes files.","Run a pre-commit encoding check on .js/.ts/.jsx/.tsx files."],"tags":["parsing","utf8","encoding","ecmascript"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}