question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Models with "@" in their name do not resolve as dependencies

See original GitHub issue

The following code examples can be copied into https://microsoft.github.io/monaco-editor/playground.html for verification.

I’m trying to specify dependencies manually via monaco.editor.createModel(), which works fine for dependency outside of organizations, but if a package is defined within a organization, i.e. has a name like @org/packagename and thus contains a @-character, it breaks. To me it looks like this is due to Monaco changing the @-character to %40.

The following code (which does not contain @) works fine:

monaco.editor.create(document.getElementById("container"), {
    model: monaco.editor.createModel(
        "import * as t from 'test';\nt.X.toExponential();\nt.Y; // Error", 
        "typescript",
        monaco.Uri.parse("file://root/test.ts")
    )
});

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
  ...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
  moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs
});

monaco.editor.createModel(
    JSON.stringify({
        name: "test", version: "1.0.0",
        typings: "./lib/index.d.ts"
    }), 
    "typescript",
    monaco.Uri.parse("file://root/node_modules/test/package.json")
);

monaco.editor.createModel(
    "export const X = 1;", 
    "typescript",
    monaco.Uri.parse("file://root/node_modules/test/lib/index.d.ts")
);

console.log(
    "Works:",
    monaco.editor.getModel("file://root/node_modules/test/lib/index.d.ts").uri.toString()
);

However, on this code (containing a @) it breaks;

monaco.editor.create(document.getElementById("container"), {
    model: monaco.editor.createModel(
        "import * as t from '@org/test';\nt.X.toExponential();\nt.Y; // Error", 
        "typescript",
        monaco.Uri.parse("file://root/test.ts")
    )
});

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
  ...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
  moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs
});

monaco.editor.createModel(
    JSON.stringify({
        name: "@org/test", version: "1.0.0",
        typings: "./lib/index.d.ts"
    }), 
    "typescript",
    monaco.Uri.parse("file://root/node_modules/@org/test/package.json")
);

monaco.editor.createModel(
    "export const X = 1;", 
    "typescript",
    monaco.Uri.parse("file://root/node_modules/@org/test/lib/index.d.ts")
);

console.log(
    "Does not work, but should:",
    monaco.editor.getModel("file://root/node_modules/@org/test/lib/index.d.ts")?.uri.toString()
);

console.log(
    "Does work, but doesnt help:",
    monaco.editor.getModel("file://root/node_modules/%40org/test/lib/index.d.ts").uri.toString()
);

monaco-editor version: 0.21.2 Browser: Chrome OS: Windows 10

Is this an issue with Monaco or with my approach? Is there a workaround for this problem? Let me know if you need more details.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
bsorrentinocommented, Apr 4, 2022

Hi

I’ve worked trying to understand the problem and finally I found out.

I’ve submitted PR #3057

4reactions
dameemshahabazcommented, Nov 24, 2021

Any update on this? I also have the same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven Could not resolve dependencies, artifacts could not be ...
The artifactId for all the dependencies that failed to download are incorrect - for some reason they are prefixed with com.springsource . Cut/paste...
Read more >
Customizing resolution of a dependency directly
In the build script, the developer declares dependencies with the module group and name, but uses a placeholder version, for example: default ....
Read more >
Introduction to the Dependency Mechanism - Apache Maven
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven ...
Read more >
Common errors - FAQ - A progressive Node.js framework
During your development with NestJS, you may encounter various errors as you learn the framework. "Cannot resolve dependency" error#. Probably the most common ......
Read more >
Resolving Dependencies - Bndtools
Unfortunately, the Maven dependency model has limitations for a number of reasons. Though it undeniably has become easier to get a result, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found