microsoft / microsoft/monaco-editor

[Bug] setExtraLibs does only work with relative paths

Open
#4,166 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request typescript typescript-multifile
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?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.40.0-dev.20230703#XQAAAAIUAgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw0eXaCAEiAKctgAboa7BDW-dD5UNujAS0b7QGpwJN09LIuNc-WgzFneLy7Iihhgtyajb-EbGjjyZzBHzOnGo_GbSrt3XR8_ZQ9Vxlw__KjuG51nRj7Q6gM5njKhM7hsDbeU_9vgXyoAAGToGYP0TTMRpo2a_UwFCzQP_E5Cwoqz4ecp52khFmSPRpjC5wrzfNh-K8uIrQzMP6cj0kSV-iEXC_jbYpilgg6kD8qTSlEyVwtCTGDL4MCVGpkC96Coiyfjo8WooJmsvFdzhAfffOYmpre8SjXnUnvR9frqdmDmIGwytNNl9QUEvArrNT624u5czPG_eSq0WvRtXLzDlxMgeq2YWD3VnJW5Ur1Bde5Z4qjKSLzjFX8xGKWWWHqfKP__lsk2s

Monaco Editor Playground Code
const value = `import { Class1 } from '/aa.js';
import { Class2 } from 'myLib';
new Class1;
new Class2;`;

monaco.languages.typescript.typescriptDefaults.setExtraLibs(
[
{content:'export class Class1 {}', filePath:'/aa.js'},
{content:'export class Class2 {}', filePath:'myLib'}
]);

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
	value,
	language: "typescript",
	automaticLayout: true,
});
Reproduction Steps

look at the playground code

Actual (Problematic) Behavior

As importmaps are now a thing, not only relative path could be used, but also some with a package name, wich is then resolved via importmap.
But the editor only works with imports with relative paths.

Expected Behavior

the sample provided should work and not show an error in the playground.

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the playground reproduction and the setExtraLibs call in the supplied TypeScript example. Trace how the TypeScript language service resolves the relative '/aa.js' and package-like 'myLib' file paths, then verify that the sample resolves both imports without an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.