microsoft / microsoft/monaco-editor

How to set alias path for files in monaco editor?

Open
#1,926 10 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

typescript upstream
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

monaco-editor version: 0.2.0
Browser: chrome
OS: mac
Playground code that reproduces the issue:

monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
    allowNonTsExtensions: true,
    allowJs: true,
    target: 99,
    paths: {
        "@/*": ["./"]
    },
    baseUrl: './',
})


const fooModel = monaco.editor.createModel(
    `export const a = {name: 'abc'}`,
    'javascript',
    monaco.Uri.parse('file:///foo.js')
);

const mainModel = monaco.editor.createModel(
    `import {a}  from '@/foo';\n`,
    'javascript',
    monaco.Uri.parse('file:///main.js')
);

monaco.editor.create(document.getElementById('container'), {model:mainModel});

import {a} from '@/foo' no syntax tips for a

Expect
a has IntelliSense

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 by running the supplied Playground code with Monaco Editor 0.2.0 and inspect how the JavaScript defaults handle the paths and baseUrl compiler options. Trace module resolution for the two created models; done means the import from '@/foo' provides IntelliSense for a.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.