microsoft / microsoft/monaco-editor

monaco-typescript not picking up configured modules from addExtraLib

Open
#754 4 comments 2 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

monaco-editor version: 0.10.1
Browser: Chrome and Edge tried, presumably any
OS: Windows 10 tried, presumably any
Steps or JS usage snippet reproducing the issue:

  1. Into the Monaco playground, type the following:
const externalDTS = `export declare function next() : string`;
const externalDTSFilename = 'external.d.ts';
const useExtraLib = true;

if (useExtraLib) {
    monaco.languages.typescript.typescriptDefaults.addExtraLib(externalDTS, externalDTSFilename);
}

var jsCode = `import * as x from "external";\nconst tt : string = x.next();`;

if (!useExtraLib) {
    var extModel = monaco.editor.createModel(externalDTS, "typescript",monaco.Uri.parse("file:///" + externalDTSFilename));
}

monaco.editor.create(document.getElementById("container"), {
    model: monaco.editor.createModel(jsCode,"typescript",monaco.Uri.parse("file:///main.tsx")), 
});
  1. Run it.
  2. Note that "external" is marked as an error - the module is not found.
  3. Flip useExtraLib to false to seed the editor with the type definition file in another file/model instead of via addExtraLib.
  4. Run it.
  5. Note that "external" now resolves correctly.

(This example is adapted from a Stack Overflow answer, which in its entirety stopped working at some point.)

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

Reproduce the issue in the Monaco playground using the provided addExtraLib and createModel snippets, then compare module resolution with and without the extra library. The work is done when the external import resolves through addExtraLib as it does when the declaration file is seeded as another model.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.