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.

[Bug] HTML language does not recognize inline <script type="module"> as JavaScript

See original GitHub issue

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 Code

monaco.editor.create(document.getElementById('container'), {
	value: `<script type="module">\n\tconsole.log("hello");\n</script>`,
	language: 'html'
});

Actual Behavior

The contents of the script tag are marked as language vs.editor.nullLanguage, precluding highlighting and, upon editing or merely moving the cursor within the tag, causing various callbacks for editor features to throw Unexpected languageId when calling LanguageConfigurationRegistry.getLanguageConfiguration.

Expected Behavior

Inline code is recognized as JavaScript, is syntax highlighted, and editing/navigation does not raise exceptions.

Additional Context

This began causing exceptions in version 0.32.0, with 0.31.1 and prior nothing is raised but the inline code is still similarly marked as vs.editor.nullMode.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
pansinmcommented, Nov 3, 2022
  1. reproducible in the monaco editor playground
monaco.editor.create(document.getElementById('container'), {
	value: "```notsupport\nerror when press enter\n```",
	language: 'markdown'
});
  1. solve this problem
+ monaco.languages.register({id: 'vs.editor.nullLanguage'})
+ monaco.languages.setLanguageConfiguration('vs.editor.nullLanguage', {})

monaco.editor.create(document.getElementById('container'), {
	value: "```notsupport\nerror when press enter\n```",
	language: 'markdown'
});
6reactions
jonatankloskocommented, Oct 9, 2022

Same with Markdown, when annotating a code code block with unknown language:

```mermaid
graph TD;
  A-->B;
  A-->C;
  B-->D;
  C-->D;
```

Error:

errors.ts:21 Uncaught Error: Language id "vs.editor.nullLanguage" is not configured nor known

Error: Language id "vs.editor.nullLanguage" is not configured nor known
    at f (languageConfigurationRegistry.ts:130:10)
    at c.getLanguageConfiguration (languageConfigurationRegistry.ts:113:13)
    at u.getLanguageConfiguration (tokenizationTextModelPart.ts:329:45)
    at u.getWordAtPosition (tokenizationTextModelPart.ts:350:9)
    at Ot.getWordAtPosition (textModel.ts:1860:42)
    at F._getWord (wordHighlighter.ts:355:21)
    at F._run (wordHighlighter.ts:373:21)
    at F._onPositionChanged (wordHighlighter.ts:347:8)
    at wordHighlighter.ts:224:9
    at t.invoke (event.ts:607:17)
    at errors.ts:26:12

(reproduced on the https://microsoft.github.io/monaco-editor playground).

Note that this worked fine on 0.33.0 and broke on 0.34.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inlining ECMAScript Modules in HTML - Stack Overflow
If you have both module and inline-module script elements in a document, their relative execution order may not be correct.
Read more >
type="module" not recognised as JavaScript
VS2017's HTML editor thinks <script type="module"> is plain text, it should be strict JS. Sample project: https://github.com/KeithHenry/VS2017-bug-script- ...
Read more >
Why can't I import a javascript module in an HTML file?
Solution 1 · 1) In Teacher.js-. Javascript. import { Person } from "./Person.js"; · 2) In Index.js-. Javascript. import { Teacher } from...
Read more >
Handling common JavaScript problems - MDN Web Docs
Maybe not so simple, but this article should at least give you a start, ... Familiarity with the core HTML, CSS, and JavaScript...
Read more >
API - esbuild
js " type="module"></script> . In node, you can load a module using node --experimental-modules file.mjs . Note that node requires the .mjs ...
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