microsoft / microsoft/monaco-editor
[Bug] Error: Could not find source file
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Code
monaco.editor.create(document.getElementById("container"), {
model: monaco.editor.createModel(
"import * as t from 'test';\nt.X.toExponential();",
"typescript",
monaco.Uri.parse("root")
)
});
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.Classic
});
const parsed = monaco.Uri.parse("/test.ts?id=123");
monaco.editor.createModel(
"export const X = 1;",
"javascript",
parsed
);
console.log(parsed)
Reproduction Steps
- Paste the code
- Open browser debug tool
- Press "Run" button
- Hover over import statement to make worker work
Actual (Problematic) Behavior
There's an error caused by adding query param (with equal sign or Russian word as example) to URI.
The problem is in method getValidSourceFile.
This file exists in the list of models, I checked this via program.getSourceFiles(), but its fileName doesn't correspond due to encoding equal sign to %3D, so the method returns undefined and console shows this error:
Uncaught (in promise) Error: Could not find source file: 'file:///test.ts?id%3D123'.
at Ve (/vs/language/typescript/tsWorker.js:255:8493)
at Object.On [as getSyntacticDiagnostics] (/vs/language/typescript/tsWorker.js:255:13349)
at lm.getSyntacticDiagnostics (/vs/language/typescript/tsWorker.js:33955:2559)
at S.fmr (workerMain.js:22:33695)
at f._handleMessage (workerMain.js:22:17684)
at Object.handleMessage (workerMain.js:22:17309)
at w._handleRequestMessage (workerMain.js:22:14120)
at w._handleMessage (workerMain.js:22:13570)
at w.handleMessage (workerMain.js:22:13458)
at f.onmessage (workerMain.js:22:17401)
Expected Behavior
File should be returned from the list of model regardless encoding/decoding issues in URI.
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Monaco Editor Playground reproduction and inspect the getValidSourceFile path used by the TypeScript worker. Verify behavior with the provided model URI containing a query parameter, and consider the issue complete when the existing model is returned despite URI encoding differences and the diagnostic request no longer reports “Could not find source file.”
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100